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

Forum statistics

Threads
473,982
Messages
2,570,186
Members
46,744
Latest member
CortneyMcK

Latest Threads

Top