Dave said:
How can I retrieve a column value from a Gridview? I've attached the
SQL String form the Sqldatasource. I'm trying to retrieve StepDate.
The columns in the Gridview are in the same order.
SELECT CONVERT (varchar(10), StepDate, 101) AS StepDate, Steps FROM
tblSteps WHERE (DomainName = @DomainName) ORDER BY StepDate DESC
Assuming that you are using an ASP.NET gridview (I'm not sure that my
response fit also windows.forms grid)
it depends on the place where you want to read the value.
If you are on Row_DataBound event you can get values from EventArgs object
(usually "e") in many ways.
I suggest you to get the object bound to the gridview instead of get values
directly from grid.
If you have a grid bound to custom objects you can get the dataobject with :
MyObject myobj = (MyObject)e.Row.DataItem;
or else if you have the grid bound with a dataset/datatable you can get the
DataRow object that contains all fields arriving from db.
DataRow myRow = (DataRow)e.Row.DataItem;
As last method you can finally use :
e.Row.Cells[0].Text
to get the value in the firs column. (0 is column index).
If you are out of grid event (like Row_DataBound) you must iterates items or
declare exact coordinates :
myGrid.Rows[0].Cells[0]
or else get the object bound to the grid :
myGrid.Rows[0].DataItem
Bob