Find the value of a read only datagrid cell

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
 
M

Marina

When it's readonly, I would imagine there is no textbox in the cell. But you
are expecting one.
 
G

Guest

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)
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,039
Latest member
CasimiraVa

Latest Threads

Top