c# - When does a Gridview have a null DataSource? -
i've read multiple sources gridview's not persist gridview.datasource property on postback. understanding in term's of asp.net, postback page load not first pageload (see msdn).
i've got situation 2 similar gridviews.
gvone.datasource null on postback.
gvtwo.datasource not null on postback.
the big difference outside of few differing columns gvone populated entity framework , linq. gvtwo populated datatable filled sqldataadapter.
further, gvone , gvtwo have templatefield textbox use gather user input. both use same code pull textbox.text on postback:
textbox tb = (textbox)gvone.rows[i].findcontrol("actualtxt");
gvone gathers tb.text. gvtwo always finds tb.text value 0.
basic gridview code:
<asp:gridview id="gvone" runat="server" autogeneratecolumns="false"> <columns> <asp:templatefield headertext="return"> <itemtemplate> <asp:textbox id="actualtxt" runat="server" text='0' width="40px"></asp:textbox> </itemtemplate> </asp:templatefield> ... </columns> </asp:gridview> <asp:gridview id="gvtwo" runat="server" autogeneratecolumns="false"> <columns> <asp:templatefield headertext="order"> <itemtemplate> <asp:textbox id="actualtxt" runat="server" text='0' width="40px"></asp:textbox> </itemtemplate> </asp:templatefield> ... </columns> </asp:gridview>
changing gvtwo use entity framework , linq potential solution, albeit major undertaking. know going on here?
update (see comment on joel etherton's answer) due popular demand here code populate gridview within page_load event gvtwo (gvone similar):
ordersgv.datasource = datasetobject.tables["activeparts"]; ordersgv.databind();
searching through code behind found no other references ordersgv.datasource , no other events hooked associated page life cycle.
gridviews not persist datasource across postbacks. if have gridview has non-null datasource must filling datasource somewhere in code. instructive travel through event cycle find population of datasource occuring on postback.
Comments
Post a Comment