c# - RowDataBound Object Not Set to an Instance of an Object -
i have gridview works fine, gives me error "object not set instance of object when edit clicked.
i believed because labels in gridview null when in edit mode , causes problem , have no idea how solve this.
<asp:boundfield datafield="received" headertext="received" sortexpression="received" readonly="true"> <itemstyle horizontalalign="center" /> </asp:boundfield> <asp:templatefield headertext="complete" sortexpression="complete"> <itemtemplate> <asp:label id="lblcomplete" runat="server" text='<%# bind("complete") %>'></asp:label> </itemtemplate> <itemstyle horizontalalign="center" /> </asp:templatefield> <asp:boundfield datafield="transtime" headertext="trans. time" sortexpression="transtime" readonly="true"> <itemstyle horizontalalign="center" /> </asp:boundfield> <asp:templatefield showheader="false"> <itemtemplate> <asp:linkbutton id="lbclose" runat="server" causesvalidation="false" commandname="closeclicked" text ="close" onclick="closeclick_click">close</asp:linkbutton> <asp:linkbutton id="lbedit" runat="server" causesvalidation="false" commandname="editrow" text ="" onclick="edit_click" commandargument='<%# eval("ticketid")%>'>edit</asp:linkbutton> <asp:linkbutton id="lbdelete" runat="server" causesvalidation="false" commandname="deleterow" text ="" onclick="delete_click">delete </asp:linkbutton> </itemtemplate> <edititemtemplate> <asp:linkbutton id="lbupdate" runat="server" causesvalidation="true" commandname="updaterow" forecolor="white" text="update" commandargument='<%# eval("ticketid")%>'></asp:linkbutton> <asp:linkbutton id="lbcancel" runat="server" causesvalidation="false" commandname="cancelupdate" forecolor="white" commandargument='<%# eval("ticketid")%>' text="cancel"></asp:linkbutton> </edititemtemplate> <footerstyle horizontalalign="center" /> <itemstyle horizontalalign="center" /> </asp:templatefield> </columns> <editrowstyle backcolor="#999999" /> /> </asp:gridview>
rowcommand
protected void gvdata_rowcommand(object sender, gridviewcommandeventargs e) { if (e.commandname == "editrow") { //this enables edittemplate int rowindex = ((gridviewrow) ((linkbutton)e.commandsource).namingcontainer).rowindex; gvdata.editindex = rowindex; //enables edit row in gridview } }
i error in lbclose.enabled
protected void gvdata_rowdatabound(object sender, gridviewroweventargs e) { e.row.cells[0].visible = false; if (e.row.rowtype == datacontrolrowtype.datarow) { linkbutton lbclose = (linkbutton)e.row.cells[5].findcontrol("lbclose"); linkbutton lbedit = (linkbutton)e.row.cells[5].findcontrol("lbedit"); linkbutton lbdelete = (linkbutton)e.row.cells[5].findcontrol("lbdelete"); var lbltrans = (label)e.row.findcontrol("lbltrans"); var lblcomplete = (label)e.row.findcontrol("lblcomplete"); if (e.row.cells[3].text == "") { lbclose.enabled = true; //error here lbedit.enabled = true; lbdelete.enabled = true; } else { lbclose.enabled = false; } } }
i believed because labels in gridview null when in edit mode , causes problem ...
ok, you're saying problem arises when enter editmode
on row. , you're right, controls don't exist in editmode
because part of itemtemplate
. this:
linkbutton lbclose = (linkbutton)e.row.cells[5].findcontrol("lbclose"); if (lbclose == null) { return; }
if can't find control know state of row , statements below don't matter.
Comments
Post a Comment