c# - How to setup paging with Gridview and code behind (no data source) -


i looking on paging using gridview , data source set in code behind. want set queries database return 50 records @ time (about 20,000 in all). works except can't paging setup properly. think default paging work, don't see anywhere can tell gridview max number of pages show in navigation or overall number of records aside 50 knows about.

i need blog or link step step instructions on how this.

here gridview:

<asp:gridview     id="gvresults"     cellpadding="4"     headerstyle-backcolor="darkgray"     runat="server"     onpageindexchanging="gvresults_pageindexchanging"     autogeneratecolumns="false" allowpaging="true" forecolor="#333333" showheaderwhenempty="true" pagesize="50" width="100%" enablesortingandpagingcallbacks="true">     <pagersettings pagebuttoncount="10" position="topandbottom" mode="numericfirstlast" />     <alternatingrowstyle backcolor="white" />     <editrowstyle backcolor="#0a5ea7" />     <footerstyle backcolor="#507cd1" font-bold="true" forecolor="white" />     <headerstyle backcolor="#0a5ea7" font-names="" font-size="medium" forecolor="white" font-bold="true"></headerstyle>     <pagerstyle backcolor="#0a5ea7" forecolor="white" horizontalalign="center" />     <rowstyle backcolor="#eff3fb" />     <selectedrowstyle backcolor="#d1ddf1" font-bold="true" forecolor="#333333" />     <sortedascendingcellstyle backcolor="#f5f7fb" />     <sortedascendingheaderstyle backcolor="#6d95e1" />     <sorteddescendingcellstyle backcolor="#e9ebef" />     <sorteddescendingheaderstyle backcolor="#4870be" />     <columns>         <asp:hyperlinkfield headertext="item number" datatextfield="change number" datatextformatstring="{0}" datanavigateurlformatstring="./item.aspx?id={0}" datanavigateurlfields="item number" />         <asp:boundfield headertext="" datafield="attachment(s)" headerimageurl="images/paperclip1sm.png" headerstyle-horizontalalign="center">             <headerstyle horizontalalign="center"></headerstyle>         </asp:boundfield>         <asp:boundfield datafield="part" headerimageurl="images/part1sm.png" headerstyle-horizontalalign="center">             <headerstyle horizontalalign="center"></headerstyle>         </asp:boundfield>         <asp:boundfield headertext="description of change" datafield="description" />         <asp:boundfield headertext="status" datafield="status" />         <asp:boundfield headertext="reason code" datafield="reason code" />         <asp:boundfield headertext="reason" datafield="reason" />     </columns> </asp:gridview> 

here query total record count:

//this total number of records.     private int getmaxrecordcount()     {         int lastrecord = 0;         string econumber = iteminput.value.toupper().trim();         string connstr = "i removed bit, work";         oracleconnection conn = new oracleconnection(connstr);         string sqlcountstring = "select count(*) table1 field1 '" + inputnumber + "%'";         conn.open();         oraclecommand cmdcount = new oraclecommand(sqlcountstring, conn);         oracledatareader countreader = cmdcount.executereader();          while (countreader.read())         {             lastrecord = int32.parse(countreader[0].tostring());             itemresults.text = "total records returned: " + lastrecord + ")";         }         conn.dispose();         return lastrecord;     } 

and here code gets subset of records:

private void bindgrid(int startrecord, int endrecord)     {         try         {             othermessage.visible = false;             othermessage.forecolor = default(color);             ecogrid.visible = false;             gvresults.visible = false;             string itemnumber = ecoinput.value.toupper().trim();             string connstr = "i removed bit, work";             oracleconnection conn = new oracleconnection(connstr);             string sqlstring = @"                                 removed bit, work                                 ";             sqlstring = sqlstring + itemnumber + "%' , rownum between " + startrecord + " , " + endrecord;              conn.open();             oraclecommand cmd = new oraclecommand(sqlstring, conn);             oracledatareader reader = cmd.executereader();             datatable dt = new datatable();             dt.columns.addrange(new datacolumn[7] {                     new datacolumn("item number"),                     new datacolumn("attachment(s)"),                     new datacolumn("part"),                     new datacolumn("status"),                     new datacolumn("reason code"),                     new datacolumn("reason"),                     new datacolumn("description")                  });              while (reader.read())             {                 datarow dr = null;                 dr = dt.newrow();                 dr["item number"] = reader[0].tostring();                 string att = hasattachments(reader[0].tostring());                 dr["attachment(s)"] = att;                 dr["part"] = "";                 dr["status"] = reader[1].tostring();                 dr["reason code"] = reader[2].tostring();                 dr["reason"] = reader[3].tostring();                 dr["description"] = reader[4].tostring();                  dt.rows.add(dr);             }              conn.dispose();              if (dt.rows.count > 0)             {                 itemgrid.visible = true;                 gvresults.visible = true;                 gvresults.datasource = dt;                 gvresults.databind();             }             else             {                 itemgrid.visible = false;                  othermessage.visible = true;                 othermessage.text = "no results found.";             }         }         catch         {             itemgrid.visible = false;             othermessage.visible = true;             othermessage.forecolor = color.red;             othermessage.text = "there error processing request. please contact helpdesk additional assistance.";         }     } 


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -