Click here to Skip to main content
11,802,442 members (71,202 online)
Rate this: bad
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 16:45pm
Edited 17-Dec-12 16:54pm
Vishal.Shimpi144 at 17-Dec-12 23:09pm
If you want ID of all your rows in 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
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
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
Please Sign up or sign in to vote.

Solution 1

Your best bet is to count the rows in the data source.
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
Please Sign up or sign in to vote.

Solution 3

Loop through the grid view[^]

This article will help you

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

  Print Answers RSS
0 OriginalGriff 465
1 KrunalRohit 366
2 F-ES Sitecore 295
3 Sergey Alexandrovich Kryukov 241
4 Afzaal Ahmad Zeeshan 230
0 OriginalGriff 2,950
1 Maciej Los 1,910
2 KrunalRohit 1,862
3 CPallini 1,645
4 Richard MacCutchan 1,157

Advertise | Privacy | Mobile
Web04 | 2.8.151002.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2015
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