【发布时间】:2014-10-30 05:24:02
【问题描述】:
我有一个在页面加载时绑定的 gridview,并且我已经使用页脚行技术实现了插入。
现在我在同一个 gridview 中尝试了分页。
我没有错误,但是在页脚行的 DDL 中更改页面时,我发现所有值都重复。
在第一页,DDL 中的输出是:
MSG
PAY
BUY
LIS
如果更改页面,第二页的第二个输出是:
MSG
PAY
BUY
LIS
MSG
PAY
BUY
LIS
如果有任何建议,我将不胜感激。
谢谢!
我在 RowDataBound 中使用了这行代码:
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow && GridView1.EditIndex == e.Row.RowIndex)
{
DropDownList Area_DDL = (DropDownList)e.Row.FindControl("Area_DDL");
Area_DDL.DataTextField = "area_name";
Area_DDL.DataValueField = "area";
Area_DDL.DataSource = Area();
Area_DDL.DataBind();
Area_DDL.Items.FindByValue((e.Row.FindControl("Area") as Label).Text).Selected = true;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
DropDownList Area_DDL = (DropDownList)e.Row.FindControl("Area_DDL");
Area_DDL.DataTextField = "area_name";
Area_DDL.DataValueField = "area";
Area_DDL.DataSource = Area();
Area_DDL.DataBind();
}
if (e.Row.RowType == DataControlRowType.Pager)
{
DropDownList ddl = (DropDownList)(e.Row.FindControl("ddlpages"));
Label lblPageCount = (Label)e.Row.FindControl("lblPageCount");
if (lblPageCount != null)
lblPageCount.Text = GridView1.PageCount.ToString();
for (int i = 1; i <= GridView1.PageCount; i++)
{
ddl.Items.Add(i.ToString());
}
ddl.SelectedIndex = GridView1.PageIndex;
if (GridView1.PageIndex == 0)
{
((ImageButton)e.Row.FindControl("ImageButton1")).Visible = false;
((ImageButton)e.Row.FindControl("ImageButton2")).Visible = false;
}
if (GridView1.PageIndex + 1 == GridView1.PageCount)
{
((ImageButton)e.Row.FindControl("ImageButton3")).Visible = false;
((ImageButton)e.Row.FindControl("ImageButton4")).Visible = false;
}
}
}
【问题讨论】:
标签: c# asp.net gridview footer