Click here to Skip to main content
15,891,943 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
VB
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id"
                                    ItemStyle-CssClass="ItemPixel" />

How to get all the values from this column of gridview in c#.

Binding grid using Datasource

ID
1
2
3

I want 1,2,3 in c# ON button click event
Posted

1 solution

Try
C#
string index = string.empty;
foreach(GridViewRow row in GridView1.Rows)
{
    index = index + "," + Convert.ToString(GridView1.Cells[0].Value);
}
return index,substring(0, index.Length - 2);
 
Share this answer
 
v3
Comments
Member 9581488 1-Feb-13 13:50pm    
GridView2.DataKeys[row.ID]
error : some invalid arg
Abhinav S 1-Feb-13 14:06pm    
Try now.
Member 9581488 1-Feb-13 14:08pm    
thank you..Its working now.I thought we have similar kind of accessibility for gridview columns like we have for row.
Thank you!

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