c# - go to a page index corresponding to a specific record in a gridview -
hello working on web page written in asp
, c#
, can add, edit , delete
records database
. web page has grid view
contains select, edit , delete links
in each row, , rows ordered dates. question is: how can insert new record, , automatically go corresponding page? (taking example grid view page size 5)
this part of grid view
<asp:gridview id="grdschedulerapplications" runat="server" autogeneratecolumns="false" visible="false" showfooter="true" pagesize="5" datakeynames="sa_id, sa_applicationid" allowpaging="true" onrowcommand="grdschedulerapplications_rowcommand"> <columns> <asp:templatefield headertext="application" headerstyle-horizontalalign="left"> <edititemtemplate> <asp:dropdownlist id="ddleditschedulerapplications" runat="server" autopostback="true" datatextfield="app_name" datavaluefield="app_id"> </asp:dropdownlist> </edititemtemplate> <itemtemplate> <%# eval("application")%> </itemtemplate> <footertemplate> <asp:dropdownlist id="ddlschedulerapplications" runat="server" autopostback="true" datatextfield="app_name" datavaluefield="app_id"> </asp:dropdownlist> </footertemplate> </asp:templatefield>
and have c# code:
protected void grdschedulerapplications_rowcommand(object sender, gridviewcommandeventargs e) { if (e.commandname.equals("insert")) { try { int saschdlrid; int.tryparse(grdbulkscheduler.selecteddatakey.values[0].tostring(), out saschdlrid); dropdownlist ddlschedulerapps = (dropdownlist)grdschedulerapplications.footerrow.findcontrol("ddlschedulerapplications"); int appid; int.tryparse(ddlschedulerapps.selectedvalue.tostring(), out appid); //calling method class add/update records database object obj = cdata.addupdatebulkschedulerapplications(0, saschdlrid, appid); //query returns automatically incremented id of newly created record obj if (obj.tostring() != "0") { //do action //here need go corresponding page index } } catch (exception ex) { //exception } }
if data source returns rows ordered date , don't modify order, need set page index , rebind grid it's data source:
if (obj.tostring() != "0") { grdschedulerapplications.pageindex = int32.parse(obj) / 5; // todo: rebind grid (set data source , call databind()) }
Comments
Post a Comment