Retrieving GridView.Rows[x].Cells[y].text when cell ReadOnly isturned off

S

S_K

Hi,

I have an editible GridView that I can read the contents of each cell
of the edit row as follows:

int iEditIndex = GridView2.EditIndex;
string strName = GridView2.Rows[iEditIndex].Cells[2].Text;

This works fine with the HTML of the cell set up as follows (note the
readonly="True"):

<asp:BoundField DataField="NET_COMPONENT_NAME"
HeaderText="NET_COMPONENT_NAME" readonly="True"
SortExpression="NET_COMPONENT_NAME" />

However, if I remove the (readonly="True") in the HTML code I just get
"" (empty string) when I try to read the contents of that cell?!

How can I retrieve the contents of a cell when the cell is designated
as NOT readonly? This is important for editing.

Thanks in advance for your help.
 
Y

Yankee Imperialist Dog

this may be because the ordinal position of the cell has changed.
a better way is to convert the cell to a template and then use findcontrol.
It's a little extra work, but it atleast lets you edit work even if you
change the order of the columns
 

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

No members online now.

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,008
Latest member
obedient dusk

Latest Threads

Top