Click here to Skip to main content
15,843,137 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

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;
 
Share this answer
 
You need to do something like this

C#
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
 
Share this answer
 
Further to Waynes Code, same in VB.NET

VB
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
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900