循环分页启用时,按钮所有的GridView行点击 [英] loop all gridview rows on button click when paging enabled
本文介绍了循环分页启用时,按钮所有的GridView行点击的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在我的GridView启用分页...
我需要在这个按钮点击事件
- 在GridView的总行数
- 通过的foreach的所有行循环
但它只能工作在当前的GridView网页...帮助
保护无效Button5_Click(对象发件人,EventArgs的)
{
INT []没有=新的INT [GridView2.Rows.Count]
INT I = 0;
的foreach(GridViewRow行GridView2.Rows)
{
标签L =(标签)row.FindControl(Label2的);
如果(l.Text ==未付款)
{
INT =的productID Convert.ToInt32(GridView2.DataKeys [row.RowIndex] .value的);
没有[我] =的productID;
我++;
}
}
}
解决方案
实现你必须循环之前禁用分页。重新绑定网格和放大器;执行循环。 然后启用分页和放大器;再次绑定网格。
保护无效Button5_Click(对象发件人,EventArgs的)
{
GridView2.AllowPaging = FALSE;
//做你的数据绑定在这里
GridView2.databind();
INT []没有=新的INT [GridView2.Rows.Count]
INT I = 0;
的foreach(GridViewRow行GridView2.Rows)
{
标签L =(标签)row.FindControl(Label2的);
如果(l.Text ==未付款)
{
INT =的productID Convert.ToInt32(GridView2.DataKeys [row.RowIndex] .value的);没有[我] =的productID;我++; }}
)
GridView2.AllowPaging = TRUE;
//做你的数据绑定在这里再次
GridView2.databind();
I have paging enabled in my gridview...
I need this in button click event
- gridview total row count
- loop through all the rows in foreach
but it's only working for the current gridview page...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++;
}
}
}
解决方案
to achieve you have to disable paging before loop. rebind the grid & perform loop . Then enable paging & bind the grid again.
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();
这篇关于循环分页启用时,按钮所有的GridView行点击的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文