Click here to Skip to main content
15,884,836 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i have a grid view which shows my data on the database, how can i access a specific cell value ??


for example i want to access the cell value saved in Row 2 and column 4 and assign it to a Label text on my page


like this: label1.text=GridView1.row(2).column(4).tostring





thanks,
Posted
Comments
F-ES Sitecore 29-Jun-15 4:49am    
The gridview is just a visual rendering of your data. If you want to know what the data in a certain "cell" is then rather than use the gridview, query the datasource the grid view is rendered from. That will give you access to the raw data, not an html rendering of it.

1 solution

try this...
C#
label1.Text=GridView1.Rows[2].Cells[4].ToString();
 
Share this answer
 
Comments
ahsal 29-Jun-15 5:22am    
Dear Nakur,

it not returns the cell's value, it returns this: System.Web.UI.WebControls.DataControlFieldCell
Ralf Meier 29-Jun-15 6:51am    
The try "label1.Text=GridView1.Rows[2].Cells[4].Value.ToString();"
ahsal 29-Jun-15 19:05pm    
Dear Ralph,
i found the solution:
label1.Text=GridView1.Rows[2].Cells[4].Text; this will return the item saved in the specified cell

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