Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C#2.0 C#3.0 C++ C++/CLI C C# ASP.NET , +
hi friends
 
i have to get the total number of rows in gridview with all values or text inside first column .. how to do it please provide me a code
 
string itemName;
List ids = new List();
 
foreach (GridViewRow item in GridView1.Rows)
{
itemName = GridView1.Rows[item].Cells[0].Text;
ids.Add(methodto get ID of text from database);
}
 
is this code correct
if not please show me the actual code
Posted 17-Dec-12 17:45pm
Edited 17-Dec-12 17:54pm
v2
Comments
Vishal.Shimpi144 at 17-Dec-12 23:09pm
   
If you want ID of all your rows in gridview....you just set the DataKeyNames property of your gridview to the ID like DataKeyNames="ID" so that you can get the value easly.
Nandakishorerao at 17-Dec-12 23:34pm
   
what is the dattsource, that you are using?..either sqldatasource or through code behind?
sreeCoderMan at 17-Dec-12 23:38pm
   
code behind
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

int count = grvTest.Rows.Count;
            foreach (GridViewRow row in grvTest.Rows)
            {
                string text = row.Cells[0].Text;
            }
 
so that you can get the cell value of 1st column of your grid view
  Permalink  
v3
Comments
sreeCoderMan at 17-Dec-12 23:51pm
   
i my project am using List id = new List();
i am adding id to my list how to retrieve all values to another page and display it
Vishal.Shimpi144 at 18-Dec-12 0:26am
   
to redirect to the next page use LinkButton.. and use PostBackUrl property to redirect like PostBackUrl="Page2.aspx". so that u can get all the controls of previous page to next page so u can access your grid to next page also.
sreeCoderMan at 18-Dec-12 0:31am
   
ok how to display this list
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Your best bet is to count the rows in the data source.
  Permalink  
Comments
sreeCoderMan at 17-Dec-12 22:55pm
   
can you tell me please
Christian Graus at 17-Dec-12 22:56pm
   
I did. Your best bet is not to ask the user interface how many rows it has, but to ask the data source you're binding to.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Loop through the grid view[^]
 

This article will help you
  Permalink  

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

  Print Answers RSS
0 OriginalGriff 431
1 Afzaal Ahmad Zeeshan 184
2 /\jmot 176
3 Sergey Alexandrovich Kryukov 175
4 Marcin Kozub 175
0 OriginalGriff 8,344
1 Sergey Alexandrovich Kryukov 7,407
2 DamithSL 5,634
3 Maciej Los 5,024
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web02 | 2.8.1411023.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100