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

Discussion in 'ASP .Net' started by S_K, Jun 5, 2008.

  1. S_K

    S_K Guest


    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

    <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.
    S_K, Jun 5, 2008
    1. Advertisements

  2. 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
    Yankee Imperialist Dog, Jun 5, 2008
    1. Advertisements

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 (here). After that, you can post your question and our members will help you out.