c# - Create multiple gridviews in code behind -


this interesting..

i want have multiple gridviews in panel. , number of gridviews not fixed..

so think there should no code in .aspx page have create gridview in codebehind.

i have code 1 gridview in 1 panel.. define grid view in html page , populate code behind.

here code that.. can 1 please me multiple gridviews...

this on .aspx page

       <asp:gridview id="gridview1" runat="server"  autogeneratecolumns="false"        allowsorting="true" cellspacing="2" onsorting="gridview1_sorting"                     width="100%" forecolor="white" gridlines="none"                        ondatabound="gridview1_databound1">         <columns>                             <edititemtemplate>                                 <asp:label id="label1" runat="server" text='<%# eval("policyid") %>'></asp:label>                             </edititemtemplate>                             <itemtemplate>                                 <asp:label id="label1" runat="server" text='<%# bind("policyid") %>'></asp:label>                             </itemtemplate>                         </asp:templatefield>       </columns>     </asp:gridview> 

this code behind

 protected void page_load(object sender, eventargs e)     {         if (!ispostback)         {             datatable dt = new datatable();             sqlconnection connection = new sqlconnection(session["connectionstringsql"].tostring());              connection.open();             sqlcommand sqlcmd = new sqlcommand("select policies.policyid, policies", connection);             sqldataadapter sqlda = new sqldataadapter(sqlcmd);              sqlda.fill(dt);             connection.close();              if (dt.rows.count > 0)             {                 (int j = 0; j < dt.rows.count; j++)                 {                     policyid.add(dt.rows[j]["policyid"].tostring());                  }                 tasktable.columns.add("policyid");                   if (policyid.count != 0)                 {                     (int k = 0; k < policyid.count; k++)                     {                         datarow tablerow = tasktable.newrow();                          tablerow["policyid"] = policyid[k];                          tasktable.rows.add(tablerow);                     }                      session["tasktable"] = tasktable;                      gridview1.datasource = session["tasktable"];                     gridview1.databind();                 }             }         }     } 

not tested, kind of thing should it:

for (int i=0;i<5;i++) {    gridview gv = new gridview();    gv.datasource = datasources[i];    page.controls.add(gv); } page.databind(); 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -