c# - Gridview Paging with Stored Procedure -
c# - Gridview Paging with Stored Procedure -
hi having issue getting gridview paging. i've read bunch of articles passing in page numbers , records per page stored procedure problem stored procedure dynamic, uses temp tables bring together on each other i've tried suggested. i'm not sure how else it. shouldn't able utilize default paging sqldatasource.
<asp:gridview id="gvfileresults" datasourceid="sqldatasource2" runat="server" autogeneratecolumns="false" emptydatatext="nothing found" allowsorting="true" allowpaging="true" pagesize="50" onpageindexchanging="gvfileresults_pageindexchanging"> <columns> <asp:hyperlinkfield datatextfield="displayname" headertext="file name" datanavigateurlfields="drawer_id, parentfolders_id, folderid, id" target="_blank" sortexpression="displayname" datanavigateurlformatstring="~/cabinet/folderview.aspx?did={0}&fid={1}&sid={2}&fileid={3}"> <controlstyle cssclass="gridlink" /> </asp:hyperlinkfield> <asp:boundfield datafield="filetype" headertext="file type" itemstyle-width="100px" sortexpression="filetype" > <itemstyle width="100px" /> </asp:boundfield> <asp:boundfield datafield="description" headertext="description" sortexpression="description" /> <asp:templatefield headertext="location" itemstyle-width="200px"> <itemtemplate> <div class="drawername"><%#eval("drawername")%></div> <div class="foldername"><%#eval("parentfoldername")%></div> <div class="subfoldername"><%#eval("foldername")%></div> </itemtemplate> <itemstyle width="200px" /> </asp:templatefield> </columns> </asp:gridview>
and have tried using stored procedure in sqldatasource code behind returns results can't paging work. , have tried using sqldatasource straight on page parameters can't homecoming results
here code datasource on page doesn't ever homecoming results
<asp:sqldatasource id="sqldatasource2" runat="server" connectionstring="<%$ connectionstrings:filecabconnection %>" selectcommand="spsearchfiles" selectcommandtype="storedprocedure"> <selectparameters> <asp:controlparameter controlid="tbfilename" defaultvalue="''" name="filename" propertyname="text" type="string" /> <asp:controlparameter controlid="tbfiledescription" name="filedescription" propertyname="text" type="string" /> <asp:controlparameter controlid="ddlfiletype" name="filetypeid" propertyname="selectedvalue" type="int32" /> <asp:controlparameter controlid="ddldrawer" name="drawerid" propertyname="selectedvalue" type="int32" /> <asp:controlparameter controlid="ddlfolder" name="folderid" propertyname="selectedvalue" type="int32" /> <asp:controlparameter controlid="ddlfolder" name="subfolderid" propertyname="selectedvalue" type="int32" /> <asp:sessionparameter name="userid" sessionfield="userid" type="int32" /> <asp:sessionparameter name="securitylevelid" sessionfield="securitylevelid" type="int32" /> </selectparameters> </asp:sqldatasource>
and here code behind datasource returns results paging doesn't work
sqldatasource1.connectionstring = configurationmanager.connectionstrings["filecabconnection"].connectionstring; sqldatasource1.selectcommand = "spsearchfiles"; sqldatasource1.selectcommandtype = sqldatasourcecommandtype.storedprocedure; sqldatasource1.selectparameters.add(new parameter("filename", dbtype.string, tbfilename.text)); sqldatasource1.selectparameters.add(new parameter("userid", dbtype.int32, user.id.tostring())); if (tbfiledescription.text != "") { sqldatasource1.selectparameters.add(new parameter("filedescription", dbtype.string, tbfiledescription.text)); } if (convert.toint32(ddlfiletype.selectedvalue) > 0) { sqldatasource1.selectparameters.add(new parameter("filetypeid", dbtype.int32, ddlfiletype.selectedvalue)); } if (convert.toint32(ddldrawer.selectedvalue) > 0 && convert.toint32(ddlfolder.selectedvalue) == 0 && convert.toint32(ddlsubfolder.selectedvalue) == 0) { sqldatasource1.selectparameters.add(new parameter("drawerid", dbtype.int32, ddldrawer.selectedvalue)); } if (convert.toint32(ddlfolder.selectedvalue) > 0 && convert.toint32(ddlsubfolder.selectedvalue) == 0) { sqldatasource1.selectparameters.add(new parameter("folderid", dbtype.int32, ddlfolder.selectedvalue)); } if (convert.toint32(ddlsubfolder.selectedvalue) > 0) { sqldatasource1.selectparameters.add(new parameter("subfolderid", dbtype.int32, ddlsubfolder.selectedvalue)); } gvfileresults.datasource = sqldatasource1; gvfileresults.databind();
add bellow 2 properties grid, enable pagination within grid. allowpaging="true" pagesize="5"
include bellow 2 parameters sql info source, pass current row index , page size.
add both page size , page index parameters sp , add together next code end of yours select statement within sp:
order [columnname] offset @pageindex * @pagesize rows fetch next @pagesize rows only;
c# asp.net sql gridview stored-procedures
Comments
Post a Comment