Find the value of a read only datagrid cell

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Help..

I have been using:
string sId =
((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
To get the value of a cell in my datagrid.

When I set the cell to read only, I get an error message.

I need to retrieve this value so I can use it in my query to update the
database.

Thanks for any help.

Jeff
 
When it's readonly, I would imagine there is no textbox in the cell. But you
are expecting one.
 
Is it read-only or disabled? If it is read-only you can read it on the server
side. Step through the code using the debugger to see if you are picking up
the right control. It is usually easier to give the control an ID, use
FindControl, check if the returned value is not null then take its value
(instead of doing all of them in one code line that throws an exception if
the control was not found where you thought it was)
 
What I said applies if the object is a read-only textbox (as it appeared to
me from your code where you cast the object to a TextBox). But if you were
attempting to retrieve the value in a cell that resulted from a BoundColumn
whose ReadOnly was set to "true" then you certainly will get an error because
a BoundColumn renders text within a TD tag (no input objects within the
rendered TD tag).

If you wanted to retrieve the values in a cell whose value you manipulated
on the client-side you would have to use HTMLInputHidden objects as I did in
this sample: http://www.societopia.net/samples/dataGrid_3.aspx

But if you were trying to retrieve the original value on datagrid cell then
you can do that from the underlying datasource.

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Phillip Williams said:
Is it read-only or disabled? If it is read-only you can read it on the server
side. Step through the code using the debugger to see if you are picking up
the right control. It is usually easier to give the control an ID, use
FindControl, check if the returned value is not null then take its value
(instead of doing all of them in one code line that throws an exception if
the control was not found where you thought it was)

--
HTH,
Phillip Williams
http://www.societopia.net
http://www.webswapp.com


Jeff said:
Help..

I have been using:
string sId =
((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
To get the value of a cell in my datagrid.

When I set the cell to read only, I get an error message.

I need to retrieve this value so I can use it in my query to update the
database.

Thanks for any help.

Jeff
 
Back
Top