动态获取可见的GridView名称 [英] Dynamically getting visible gridview names

查看:61
本文介绍了动态获取可见的GridView名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我有20个静态的gridviews,即它们是在设计视图中创建的,但不是在运行时创建的.现在显示了这些网格视图,即基于一个查询将其可见性设置为true,这显示了应该看到多少个网格视图.

现在这些可见的网格视图中有很多数据,即每个网格视图中可能都有行.

现在,我想将每个gridview的每个行数据保存在数据库的临时表中.

现在,我已经编写了这样的代码,该计数器用于显示多少个网格视图,并根据其计数器行获取并插入到数据库中.但是我的指南不希望这样做.

他想要的是在一个循环中完成所有操作,例如,然后可见三(3)个网格视图.首先,它应该读取第一个gridview的每一行,然后在它的行完成后就应该进入下一个gridview ..但是,当按名称提取gridview行时,像gridview1.rows [i]那样,怎么可能呢. cells [j] .text,其中gridview1是gridview的名称...


请帮帮我..


谢谢&问候,
Krunal Panchal

Hello everyone,

I have 20 gridviews which are static i.e. they are created in design view only not created at runtime. Now these gridviews are shown i.e. their visibility is set to true on basis of one query ,which shows how many gridviews should be visible.

Now these visible gridviews have many data in it i.e. there are may rows in each gridview.

Now i want to save each and every row data of each and every gridview in temporary table of database.

Now i have written code like this, that counter for how many gridviews are visible and on the basis of their counter rows are fetched and inserted to database..but my guide doesn''t wants this.

What he wants is to do everything in one loop i.e. for example three (3) gridviews are visible then. first it should read each row of 1st gridview , then as soon as its rows are completed it should go to next gridview.. but how could it be possible when i m fetching gridview rows by its name.. like gridview1.rows[i].cells[j].text where gridview1 is name of gridview...


Please help me out..


Thanks & Regards,
Krunal Panchal

推荐答案

如果您的gridviews名称包含一些一致的样式,例如gridview1,gridview2,gridview3 ....等等.
我想,您可以只用一个循环就能做到这一点.只需将变量计数器值与"gridview"常量名称相加即可.
在那个循环中,您可以获得的总行数为

var grid = document.getelementById("gridview" + counter);

var totalrows = grid.rows.count;
If your gridviews name are folowing some consistent pattren like gridview1, gridview2, gridview3.... so on.
you can do it with one loop only i think. by just adding the variable counter value with the "gridview" constant name.
and in that loop you can get total rows as

var grid = document.getelementById("gridview"+counter);

var totalrows = grid.rows.count;


您需要执行以下操作

You need to do something like this

foreach (Control ctrl in this.Controls)
            {
                if (ctrl is DataGridView && ctrl.Visible == true)
                {
                    DataGridView dgv = ctrl as DataGridView;
                    foreach (DataGridViewRow row in dgv.Rows)
                    {
                        //commit to database
                    }
                }
            }



希望对您有所帮助



Hope this helps


进一步进行韦恩斯代码,与VB.NET中的相同

Further to Waynes Code, same in VB.NET

for each crtl as control in me.controls
  if typeof ctrl is datagridview and ctrl.visible = true then
    for each row as datagridviewrow in ctrl.rows
      'commit to database
    next
  end if
next


这篇关于动态获取可见的GridView名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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