datagrid| pagination | Sorting when the DataGrid has both paging and sorting capabilities, you should be aware that when you rebind the data source, mydatagrid.currentpageindex=0;
The following to achieve the above function of the original code, it is not a lot of suffix
ASPX contains a DataGrid and DropDownList that control its data source changes
DataGrid Code
<asp:datagrid id= "Mydatagrid" runat= "Server" bordercolor= "#CCCCCC" font-size= "100%" horizontalalign= "Center"
autogeneratecolumns= "False" ondeletecommand= "Mydatagrid_delete" onsortcommand= "Sort_grid" OnPageIndexChanged= " Mydatagrid_pageindexchanged "
Datakeyfield= "Acc_no" pagerstyle-position= "Bottom" pagerstyle-horizontalalign= "Center" pagerstyle-mode= "NextPrev"
Pagesize= "allowsorting=" "true" allowpaging= "true" cellpadding= "4" width= "100%" >
<alternatingitemstyle backcolor= "#E9E9E6" ></AlternatingItemStyle>
<Columns>
<asp:buttoncolumn text= "Kou" commandname= "Delete" ></asp:ButtonColumn>
<asp:boundcolumn datafield= "No" sortexpression= "no" readonly= "True" headertext= "Serial number" ></asp:BoundColumn>
<asp:boundcolumn datafield= "id" sortexpression= "id" headertext= "id" ></asp:BoundColumn>
<asp:boundcolumn datafield= ' name ' sortexpression= ' name ' headertext= ' names ' ></asp:BoundColumn>
<asp:boundcolumn datafield= "C_name" sortexpression= "C_name" headertext= "section name" ></asp:BoundColumn>
<asp:boundcolumn datafield= "FLG" sortexpression= "FLG" headertext= "project" ></asp:BoundColumn>
</Columns>
<pagerstyle nextpagetext= "Next 10" prevpagetext= "Back" horizontalalign= "Center" ></PagerStyle>
</asp:datagrid>
<summary>///</summary>
private void InitializeComponent ()
{
This.ddlWk.SelectedIndexChanged + = new System.EventHandler (this.ddlwk_selectedindexchanged);
This. Load + = new System.EventHandler (this. Page_Load);
}
#endregion
private void Ddlwk_selectedindexchanged (object sender, System.EventArgs e)
{
session["WP"]=ddlwk.selectedvalue;
mydatagrid.currentpageindex=0;//without this, an error occurs when the page number exceeds the range of other data sources
Bindgrid ();
Response.Write ("<script language= ' JavaScript ' >parent.menuframe.location.reload ();</script>");
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.