Click here to Skip to main content
12,953,349 members (54,004 online)
Rate this:
Please Sign up or sign in to vote.
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<int32> ids = new List<int32>();

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
Updated 17-Dec-12 16:54pm
Vishal.Shimpi144 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 17-Dec-12 23:34pm
what is the dattsource, that you are using?..either sqldatasource or through code behind?
sreeCoderMan 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 17-Dec-12 23:51pm
i my project am using List<int32> id = new List<int32>();
i am adding id to my list how to retrieve all values to another page and display it
Vishal.Shimpi144 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 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 17-Dec-12 22:55pm
can you tell me please
Christian Graus 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
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
Jochen Arndt 1,975
ppolymorphe 1,930

Advertise | Privacy | Mobile
Web01 | 2.8.170525.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2017
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