DropDownList和dataGrid联动后的分页出错,请达人指点....
页面有DropDownList和DataGrid控件,已用dropdownlist的AutoPostBack回传功能实现了联动邦定在datagrid上,datagrid分页也没有问题,但是当datagrid的页码不在第一页时(也就是currentPageIndex>1时),改取dropdownlist的值的化,就会出现错误提示:"无效的 CurrentPageIndex 值。它必须大于等于 0 且小于 PageCount。 "我想可能是重新邦定时CurrentPageIndex的取值不对造成的,要怎么解决呢??
apx代码(由于太多,只列相关部份):
<asp:DropDownList ID="ddlShowType" runat="server" AutoPostBack="True" OnSelectedIndexChanged="ddlShowType_SelectedIndexChanged">
</asp:DropDownList>
<asp:DataGrid ID="dgShowTodayInput" runat="server" AutoGenerateColumns="False" AllowPaging="True" PageSize="5" OnPageIndexChanged="dgShowTodayInput_PageIndexChanged" >
<PagerStyle NextPageText="下一页" PrevPageText="上一页" Mode="NumericPages" />
</asp:DataGrid>
aspx.cs代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.bindddlType();//调用邦定ddlShowType
this.bindShowTodayInput();//调用邦定datagrid
}
}
///邦定ddlShowType
private void bindddlType()
{
DataSet ds = db.returnDs("select insuID,insuName from insuType");
this.ddlShowType.DataSource = ds.Tables["Table"];
this.ddlShowType.DataValueField = "insuID";
this.ddlShowType.DataTextField = "insuName";
this.ddlShowType.DataBind();
}
//当dropdownList值改变时,重新邦定datagrid
protected void ddlShowType_SelectedIndexChanged(object sender, EventArgs e)
{
this.bindShowTodayInput();
}
//邦定dataGrid
private void bindShowTodayInput()
{
string phType = this.ddlShowType.SelectedItem.Text;
DataSet ds = db.returnDs("select * from phDetailes where phType='" + phType + "' and ifUse='1'");
this.dgShowTodayInput.DataKeyField = "phID";
this.dgShowTodayInput.DataSource = ds.Tables["Table"];
this.dgShowTodayInput.DataBind();
}
//分页
protected void dgShowTodayInput_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
this.dgShowTodayInput.CurrentPageIndex = e.NewPageIndex;
this.bindShowTodayInput();
}