Cant reference cell text

Discussion in 'ASP .Net Datagrid Control' started by Assimalyst, Sep 5, 2005.

  1. Assimalyst

    Assimalyst Guest

    Hi,

    I'm attempting an update SQl Server using a gatagrid using ADO.

    I am having trouble getting a changed value to work however.

    The datagrid is populated as below:

    sampleNo brush biopsy lavage histology patinetNo
    Edit 87 True True True Squamous 67

    The only editable column is histology.

    I am using the following code to try to update any changes to that
    cell:

    DataRow sRow = dsSample.Tables["Table"].Rows[0];
    sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];

    But no update occurs. If i change it to:

    DataRow sRow = dsSample.Tables["Table"].Rows[0];
    sRow["Histology"] = "New Text";

    Then it does update. So it seems my cell referencing is wrong. Can
    anyone tell me why? I have tried changing the [5] and [0], but get
    errors.

    Thanks.
    Assimalyst, Sep 5, 2005
    #1
    1. Advertising

  2. Assimalyst

    Brock Allen Guest

    Put a breakpoint in the debugger to see how many child controls are under
    the Cell -- there may be more than one if it's a template column.

    -Brock
    DevelopMentor
    http://staff.develop.com/ballen



    > Hi,
    >
    > I'm attempting an update SQl Server using a gatagrid using ADO.
    >
    > I am having trouble getting a changed value to work however.
    >
    > The datagrid is populated as below:
    >
    > sampleNo brush biopsy lavage histology patinetNo
    > Edit 87 True True True Squamous 67
    >
    > The only editable column is histology.
    >
    > I am using the following code to try to update any changes to that
    > cell:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];
    > But no update occurs. If i change it to:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = "New Text";
    > Then it does update. So it seems my cell referencing is wrong. Can
    > anyone tell me why? I have tried changing the [5] and [0], but get
    > errors.
    >
    > Thanks.
    >
    Brock Allen, Sep 5, 2005
    #2
    1. Advertising

  3. Assimalyst

    Assimalyst Guest

    Thanks for the suggestion Brock.

    I've put a breakpoint in the debugger, i then expanded 'e' then 'Item'
    and found there are listings for 'Cells' and 'cells', i've expanded
    these and the 'owner', then get an option again of expanding 'Cells'
    and 'cells' (amongst others), and it seems i can continue expanding
    'Cells' then 'owner' for quite some time . . .

    Not really sure what i'm looking for from here. Could you point me in
    the right direction please?

    Thanks again.
    Assimalyst, Sep 6, 2005
    #3
  4. Assimalyst

    Elton Wang Guest

    You can't assign a control, TextBox, to ["Histology"]. You should use a
    string value to update sRow["Histology"] like :
    TextBox txtHistology = ((TextBox)e.Item.Cells[5].Controls[0];
    sRow["Histology"] = txtHistology.Text;


    HTH



    "Assimalyst" <> wrote in message
    news:...
    > Hi,
    >
    > I'm attempting an update SQl Server using a gatagrid using ADO.
    >
    > I am having trouble getting a changed value to work however.
    >
    > The datagrid is populated as below:
    >
    > sampleNo brush biopsy lavage histology patinetNo
    > Edit 87 True True True Squamous 67
    >
    > The only editable column is histology.
    >
    > I am using the following code to try to update any changes to that
    > cell:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = ((TextBox)e.Item.Cells[5].Controls[0];
    >
    > But no update occurs. If i change it to:
    >
    > DataRow sRow = dsSample.Tables["Table"].Rows[0];
    > sRow["Histology"] = "New Text";
    >
    > Then it does update. So it seems my cell referencing is wrong. Can
    > anyone tell me why? I have tried changing the [5] and [0], but get
    > errors.
    >
    > Thanks.
    >
    Elton Wang, Sep 6, 2005
    #4
  5. Assimalyst

    Assimalyst Guest

    Thanks Elton,

    Tried that, but still getting the same behaviour as above. The database
    is not updating.

    I can only presume something is wrong with the
    ((TextBox)e.Item.Cells[5].Controls[0]) statement. But what??

    Thanks again.
    Assimalyst, Sep 6, 2005
    #5
  6. Assimalyst

    Elton Wang Guest

    One most likely reason is that data in the textbox is overwritten by data
    from database. You might rebind the datagrid's data source before performing
    update function. Normally, we should bind the datagrid's data source when
    IsPostback = false.



    HTH





    "Assimalyst" <> wrote in message
    news:...
    > Thanks Elton,
    >
    > Tried that, but still getting the same behaviour as above. The database
    > is not updating.
    >
    > I can only presume something is wrong with the
    > ((TextBox)e.Item.Cells[5].Controls[0]) statement. But what??
    >
    > Thanks again.
    >
    Elton Wang, Sep 6, 2005
    #6
    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. news.rcn.com
    Replies:
    1
    Views:
    9,666
    Chris Smith
    Jul 12, 2004
  2. Phillip Roncoroni
    Replies:
    14
    Views:
    1,090
    Toby A Inkster
    Apr 5, 2004
  3. Nagaraj
    Replies:
    1
    Views:
    856
    Lionel B
    Mar 1, 2007
  4. GideonPrior

    Cant Add reference (.dll) in VS C++ express

    GideonPrior, Jun 22, 2007, in forum: C Programming
    Replies:
    0
    Views:
    641
    GideonPrior
    Jun 22, 2007
  5. Mark
    Replies:
    2
    Views:
    84
    Egbert Beuker
    Sep 15, 2003
Loading...

Share This Page