如何使用for循环修改多个控件(gridview) [英] How to use a for loop to modify multiple controls (gridview)

查看:248
本文介绍了如何使用for循环修改多个控件(gridview)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



比方说,我有10个gridview命名为Gridview1,我们可以使用一个GridView1 ,Gridview2,Gridview3 ...等。



我可以写一些类似于

  for(int i = 1; i< = 10; i ++)
{
Gridview [i] .Rows [1] ...
}

希望我已经清楚了,对不起我的英语。

解决方案

您可以使用 foreach 循环。像这样。

  foreach(Page.Controls.OfType中的GridView gv< GridView>())
{
gv.Rows [1] .........
}

其他方法,如果您使用的是2.0版本(b = b

  for(int i = 1; i <= 10; i ++)
{
((GridView)Page.FindControl(GridView+ i))。行[1] .........
}

有关foreach的更多信息 OfType


Hello everyone Is it possible to use a for loop to cycle through a set of gridviews and modify each one of them?

Let's say I have 10 gridviews named Gridview1, Gridview2, Gridview3...and so on.

Can i write something like

for(int i=1; i<=10;i++)
{
    Gridview[i].Rows[1]...
}

Hope I was clear enough, sorry for my english.

解决方案

You can use foreach loop. like this.

        foreach (GridView gv in Page.Controls.OfType<GridView>())
        {
           gv.Rows[1].........
        }

Other approach, if you are using 2.0 version

for(int i=1; i<=10; i++)
{
     ((GridView) Page.FindControl("GridView" + i)).Rows[1].........
}

More about foreach and OfType

这篇关于如何使用for循环修改多个控件(gridview)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆