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

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

  2. RE: Retrieving GridView.Rows[x].Cells[y].text when cell ReadOnly is tu

    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

    --
    Share The Knowledge. I need all the help I can get and so do you!


    "S_K" wrote:

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

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Stephan Bour

    Retrieving text from DataList cells

    Stephan Bour, Dec 16, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    1,174
    Bin Song
    Dec 17, 2003
  2. Joel Finkel

    Cells[].Text or Cells[].Controls[0]

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    319
    Joel Finkel
    Sep 1, 2003
  3. Jonathan Hyatt
    Replies:
    1
    Views:
    2,024
    Jonathan Hyatt
    Jun 8, 2004
  4. vinda

    Set Gridview Edit cell to Readonly Bug

    vinda, Jun 13, 2006, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    242
    vinda
    Jun 13, 2006
  5. Tony Cooke
    Replies:
    7
    Views:
    146
    Tony Cooke
    Jan 21, 2004
Loading...

Share This Page