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

ice2927276 2007-02-15 11:14:35
页面有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();
}
...全文
292 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
xiaoqhuang 2007-02-15
  • 打赏
  • 举报
回复
//当dropdownList值改变时,重新邦定datagrid
protected void ddlShowType_SelectedIndexChanged(object sender, EventArgs e)
{
this.dgShowTodayInput.CurrentPageIndex=0
this.bindShowTodayInput();
}
ice2927276 2007-02-15
  • 打赏
  • 举报
回复
谢谢两位,二楼的正解,我怎么没想到呢,郁闷,,,,同样谢谢三楼的,虽然我没看懂你写的是怎么回事,
viva369 2007-02-15
  • 打赏
  • 举报
回复
//分页
protected void dgShowTodayInput_PageIndexChanged(object source, DataGridPageChangedEventArgs e)
{
bindShowTodayInput //需要重新绑定数据源,否之e.NewPageIndex为null了
this.dgShowTodayInput.CurrentPageIndex = e.NewPageIndex;
// this.bindShowTodayInput();
dgShowTodayInput.DataBind();
}

62,074

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧