Friday 15 February 2013

c# - asp.net GridView table won't display if container div is set invisible during page load -



c# - asp.net GridView table won't display if container div is set invisible during page load -

i have 2 gridviews in asp webform project, 1 display , 1 edit. have them each in separate div. start edit div invisible, , have button in display div makes display div invisible , edit div visible. basic code looks this:

<div id="displaydiv"> <asp:gridview id="certlist" runat="server" autogeneratecolumns="false" datasourceid="getmydata"> <columns> <asp:boundfield datafield="a few datafields go here /> </columns> </asp:gridview> <asp:button id="btnedit" runat="server" onclick="btnedit_click" text="edit" /> </div> <div id="editdiv" visible="false"> <asp:gridview id="certlist" runat="server" autogeneratecolumns="false" datasourceid="getmydata" "> <columns> <asp:boundfield datafield="a few datafields go here /> </columns> </asp:gridview> </div>

the click event button looks this:

protected void btnedit_click(object sender, eventargs e) { editdiv.visible = true; displaydiv.visible = false; }

everything works fine plumbing if don't set editdiv's visible attribute false in markup. if set false, table doesn't show when set true programmatically in button click event. seems dataview's rendering capability tied ability access markup. so, based on theory, tried setting position absolute , left -10000 , got same result.

is can't do, or missing something?

edit: set test @ home , works fine:

<asp:content id="bodycontent" runat="server" contentplaceholderid="maincontent"> <div id="div1" runat="server"> <asp:gridview id="gridview1" runat="server" autogeneratecolumns="false" datakeynames="customerid" datasourceid="sqldatasource1"> <columns> <asp:boundfield datafield="customerid" headertext="customerid" readonly="true" sortexpression="customerid" /> <asp:boundfield datafield="companyname" headertext="companyname" sortexpression="companyname" /> <asp:boundfield datafield="contactname" headertext="contactname" sortexpression="contactname" /> <asp:boundfield datafield="contacttitle" headertext="contacttitle" sortexpression="contacttitle" /> </columns> </asp:gridview> <asp:button id="button1" runat="server" onclick="button1_click" text="button1" /> </div> <div id="div2" runat="server" visible="false"> <asp:gridview id="gridview2" runat="server" autogeneratecolumns="false" datakeynames="productid" datasourceid="sqldatasource2"> <columns> <asp:boundfield datafield="productid" headertext="productid" insertvisible="false" readonly="true" sortexpression="productid" /> <asp:boundfield datafield="productname" headertext="productname" sortexpression="productname" /> <asp:boundfield datafield="unitsinstock" headertext="unitsinstock" sortexpression="unitsinstock" /> </columns> </asp:gridview> <asp:button id="button2" runat="server" onclick="button2_click" text="button2" /> </div> <asp:sqldatasource id="sqldatasource1" runat="server" connectionstring="<%$ connectionstrings:northwindconnectionstring %>" selectcommand="select top (5) customerid, companyname, contactname, contacttitle customers"> </asp:sqldatasource> <asp:sqldatasource id="sqldatasource2" runat="server" connectionstring="<%$ connectionstrings:northwindconnectionstring %>" selectcommand="select top (5) * products"> </asp:sqldatasource> </asp:content>

and code behind:

protected void button1_click(object sender, eventargs e) { div1.visible = false; div2.visible = true; } protected void button2_click(object sender, eventargs e) { div2.visible = false; div1.visible = true; }

so there's proof of concept. it's silly mistake, i'll post 1 time find out story is.

set runat="server" both divs seek access code behind.

<div id="displaydiv" runat="server"> .... </div> <div id="editdiv" runat="server" visible="false"> .... </div>

or can utilize asp:panel instead of div can access visible property code behind.

<asp:panel id ="pnldisplay" runat="server"> .... </asp:panel> <asp:panel id ="pnledit" runat="server" visible="false"> .... </asp:panel>

and code behind

protected void btnedit_click(object sender, eventargs e) { pnldisplay.visible = false; pnledit.visible = true; }

c# asp.net gridview webforms

No comments:

Post a Comment