c# - Panel is Invisible but children are databinding -


i have panel in asp.net control. when invisible gridviews in panel databinding. don't want them when panel invisible. following solution presented. solution placeholders , have tried implement panels

public class newpanel : panel {     protected override void databindchildren()     {         if (visible)         {             base.databindchildren();         }     } } 

my question how use newpanel class in markup in .aspx page ? or there way override method in panelin code dynamically , keep using panel in markup ?

this portion of aspx code

<asp:gridview id="assignedgv" runat="server" autogeneratecolumns="false" datakeynames="orderid" datasourceid="assignedds" width="100%">       <columns>            <asp:templatefield headertext="created" sortexpression="dateordercreated">                   <itemtemplate>                        <asp:label id="label1" runat="server" text='<%# bind("dateordercreated", "{0:d-mmm-yyyy}") %>'></asp:label>                   </itemtemplate>  <asp:sqldatasource id="assignedds" runat="server" connectionstring="<%$ connectionstrings:xxxxxxx %>" selectcommand="select top (100) percent t_orders.orderid, xxxxxxxxxxxxxxxxx orderquoteversion.requestapprovalofemployeeid, t_orders.jobnumber xxxxxxx t_orderquoteversion right outer join xxxxx t_orders inner join xxxxxxx on t_orders.customerid = t_customers.customerid on t_orderquoteversion.orderid = t_orders.orderid  "></asp:sqldatasource> 

this code within panel , gets databinded regardless if panel invisible or not

i databind in code behind , use approach here find gives more control. i'll interested in seeing answers maintain use of sqldatasource control.

the change need make aspx remove sqldatasource control.

in code behind you'll want like

//put in pageload or load, ever suits best //the ispostback check optional....remove if fits tour needs better if(!ispostback) {     //use appropriate panel id below     if(panelid.visible)     {         string constring = "your connection string";         using (sqlconnection con = new sqlconnection(constring))         {             using (sqlcommand cmd = new sqlcommand("your sql query", con))             {                 cmd.commandtype = commandtype.text;                 using (sqldataadapter sda = new sqldataadapter(cmd))                {                     using (datatable dt = new datatable())                     {                         sda.fill(dt);                         assignedgv.datasource = dt;                         assignedgv.databind();                     }                }             }          }     } } 

note haven't tested code, may have typos or other stupid errors should enough moving in right direction.


Comments

Popular posts from this blog

node.js - Node js - Trying to send POST request, but it is not loading javascript content -

javascript - Replicate keyboard event with html button -

javascript - Web audio api 5.1 surround example not working in firefox -