Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Updated 17-Dec-12 16: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.
Nandakishore G N 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

C#
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
 
Share this answer
 
v3
Comments
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
Your best bet is to count the rows in the data source.
 
Share this answer
 
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.
Loop through the grid view[^]


This article will help you
 
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