<asp:Repeater runat="server" ID="rptChilds"> <ItemTemplate> <asp:CheckBox ID="chkc" runat="server" Text="" /> <br /> </ItemTemplate> </asp:Repeater>
for (j = 0; j < NumberOfCheckboxes; j++) { CheckBox chk = (CheckBox)(rptChilds).FindControl("chkc"); if (chk != null) { if (chk.Checked) //do something here } else { //error } }
Server Error in '/Project' Application. Object reference not set to an instance of an object. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.NullReferenceException: Object reference not set to an instance of an object. Source Error: Line 250: { Line 251: CheckBox chk = (CheckBox)(rptChilds).FindControl("chkc"); Line 252: if (chk.Checked) Line 253: { Line 254: //your code here Source File: f:\Documents\ \Projects\MahdZNU\Project\Pages\Image Gallery\showImages.aspx.cs Line: 252 Stack Trace: [NullReferenceException: Object reference not set to an instance of an object.] Pages_Image_Gallery_showImages.insertImageIntoGallery(Object sender, EventArgs e) in f:\Documents\ \Projects\MahdZNU\Project\Pages\Image Gallery\showImages.aspx.cs:252 System.Web.UI.WebControls.LinkButton.OnClick(EventArgs e) +116 System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +101 System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10 System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13 System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9642898 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
foreach (RepeaterItem item in rptChilds.Items) { if (item.ItemType == ListItemType.Item || item.ItemType == ListItemType.AlternatingItem) { CheckBox chk = (CheckBox)(rptChilds).FindControl("chkc"); if (chk.Checked) { //your code here } else { //your code here } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)