我在gridview中启用了分页...
我在按钮点击事件中需要这个
但它仅适用于当前的gridview页面... help
protected void Button5_Click(object sender, EventArgs e)
{
int[] no = new int[GridView2.Rows.Count];
int i = 0;
foreach (GridViewRow row in GridView2.Rows)
{
Label l = (Label)row.FindControl("Label2");
if (l.Text == "Unpaid")
{
int productID = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value);
no[i] = productID;
i++;
}
}
}
答案 0 :(得分:3)
实现你必须在循环之前禁用分页。重新绑定网格&执行循环。 然后启用分页&再次绑定网格。
protected void Button5_Click(object sender, EventArgs e)
{
GridView2.AllowPaging = false;
// do your databind here
GridView2.databind();
int[] no = new int[GridView2.Rows.Count];
int i = 0;
foreach (GridViewRow row in GridView2.Rows)
{
Label l = (Label)row.FindControl("Label2");
if (l.Text == "Unpaid")
{
int productID = Convert.ToInt32(GridView2.DataKeys[row.RowIndex].Value); no[i] = productID; i++; } }
)
GridView2.AllowPaging = true;
// do your databind here again
GridView2.databind();