双11狂欢大促

盲盒赢 定制羽绒服

开启惊喜盲盒,抽取你的专属好礼

— 惊喜奖品抢先看 —

DropDownList和dataGrid联动后的分页出错,请达人指点....

ice2927276 ice2927276 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
页面有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();
}
...全文

相关推荐

评论 3
收藏 已收藏
分享
返回顶部
ice2927276
.NET社区 62,274 成员 668,968 内容