Find the value of a read only datagrid cell

Discussion in 'ASP .Net' started by =?Utf-8?B?SmVmZg==?=, Nov 29, 2005.

  1. Help..

    I have been using:
    string sId =
    ((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
    To get the value of a cell in my datagrid.

    When I set the cell to read only, I get an error message.

    I need to retrieve this value so I can use it in my query to update the
    database.

    Thanks for any help.

    Jeff
    =?Utf-8?B?SmVmZg==?=, Nov 29, 2005
    #1
    1. Advertising

  2. =?Utf-8?B?SmVmZg==?=

    Marina Guest

    When it's readonly, I would imagine there is no textbox in the cell. But you
    are expecting one.

    "Jeff" <> wrote in message
    news:...
    > Help..
    >
    > I have been using:
    > string sId =
    > ((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
    > To get the value of a cell in my datagrid.
    >
    > When I set the cell to read only, I get an error message.
    >
    > I need to retrieve this value so I can use it in my query to update the
    > database.
    >
    > Thanks for any help.
    >
    > Jeff
    Marina, Nov 29, 2005
    #2
    1. Advertising

  3. Is it read-only or disabled? If it is read-only you can read it on the server
    side. Step through the code using the debugger to see if you are picking up
    the right control. It is usually easier to give the control an ID, use
    FindControl, check if the returned value is not null then take its value
    (instead of doing all of them in one code line that throws an exception if
    the control was not found where you thought it was)

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Jeff" wrote:

    > Help..
    >
    > I have been using:
    > string sId =
    > ((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
    > To get the value of a cell in my datagrid.
    >
    > When I set the cell to read only, I get an error message.
    >
    > I need to retrieve this value so I can use it in my query to update the
    > database.
    >
    > Thanks for any help.
    >
    > Jeff
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 29, 2005
    #3
  4. What I said applies if the object is a read-only textbox (as it appeared to
    me from your code where you cast the object to a TextBox). But if you were
    attempting to retrieve the value in a cell that resulted from a BoundColumn
    whose ReadOnly was set to "true" then you certainly will get an error because
    a BoundColumn renders text within a TD tag (no input objects within the
    rendered TD tag).

    If you wanted to retrieve the values in a cell whose value you manipulated
    on the client-side you would have to use HTMLInputHidden objects as I did in
    this sample: http://www.societopia.net/samples/dataGrid_3.aspx

    But if you were trying to retrieve the original value on datagrid cell then
    you can do that from the underlying datasource.

    --
    HTH,
    Phillip Williams
    http://www.societopia.net
    http://www.webswapp.com


    "Phillip Williams" wrote:

    > Is it read-only or disabled? If it is read-only you can read it on the server
    > side. Step through the code using the debugger to see if you are picking up
    > the right control. It is usually easier to give the control an ID, use
    > FindControl, check if the returned value is not null then take its value
    > (instead of doing all of them in one code line that throws an exception if
    > the control was not found where you thought it was)
    >
    > --
    > HTH,
    > Phillip Williams
    > http://www.societopia.net
    > http://www.webswapp.com
    >
    >
    > "Jeff" wrote:
    >
    > > Help..
    > >
    > > I have been using:
    > > string sId =
    > > ((System.Web.UI.WebControls.TextBox)e.Item.Cells[2].Controls[0]).Text;
    > > To get the value of a cell in my datagrid.
    > >
    > > When I set the cell to read only, I get an error message.
    > >
    > > I need to retrieve this value so I can use it in my query to update the
    > > database.
    > >
    > > Thanks for any help.
    > >
    > > Jeff
    =?Utf-8?B?UGhpbGxpcCBXaWxsaWFtcw==?=, Nov 29, 2005
    #4
    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. keithb
    Replies:
    2
    Views:
    7,990
    keithb
    Jun 7, 2006
  2. =?Utf-8?B?bWlrZWc=?=

    ASP1 DataGrid Cannot Update /Read entered cell value.

    =?Utf-8?B?bWlrZWc=?=, Jun 26, 2007, in forum: ASP .Net
    Replies:
    0
    Views:
    390
    =?Utf-8?B?bWlrZWc=?=
    Jun 26, 2007
  3. Empire City
    Replies:
    3
    Views:
    389
    Empire City
    Apr 30, 2004
  4. RJ
    Replies:
    1
    Views:
    229
    Eliyahu Goldin
    Feb 17, 2005
  5. Don Hans

    find value of cell in datagrid?

    Don Hans, Dec 18, 2003, in forum: ASP .Net Web Controls
    Replies:
    3
    Views:
    531
    Mike Moore [MSFT]
    Dec 19, 2003
Loading...

Share This Page