Click here to Skip to main content
12,064,207 members (58,717 online)
Rate this:
 
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 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 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
 
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 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 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
 
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 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
 
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
Top Experts
Last 24hrsThis month


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