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

  • Thread starter Thread starter S_K
  • Start date Start date
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.
 
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
 
Back
Top