Simple question: e.Item.Cells(0).Controls­(0)

Discussion in 'ASP .Net Datagrid Control' started by davidfox789@hotmail.com, Aug 2, 2005.

  1. Guest

    I am new at this.. probably not proficient enough to even consider
    myself a Newbie yet. :)

    I have a DataGrid with Template columns. After the user edits a field
    in the DataGrid and presses Update, the UpdateCommand code executes no
    problem. However...

    Normally I read the newly edited contents of a cell thusly:

    Dim tb As TextBox
    tb = CType(e.Item.Cells(1).Controls(0), TextBox)

    However! A DataGrid I created today will only work if I reference
    Controls(1) rather than Controls(0):

    Dim tb As TextBox
    tb = CType(e.Item.Cells(1).Controls(1), TextBox)

    Could someone please shed some light on how an attribute can "move
    around" inside a control, in this case from position 0 to position 1?

    I don't want them moving around after I'm done. :)
     
    , Aug 2, 2005
    #1
    1. Advertising

  2. Elton Wang Guest

    The better way is to use

    Dim tb As TextBox = CType(e.Item.FindControl(textbox_ID), TextBox)

    HTH

    <> wrote in message
    news:...
    > I am new at this.. probably not proficient enough to even consider
    > myself a Newbie yet. :)
    >
    > I have a DataGrid with Template columns. After the user edits a field
    > in the DataGrid and presses Update, the UpdateCommand code executes no
    > problem. However...
    >
    > Normally I read the newly edited contents of a cell thusly:
    >
    > Dim tb As TextBox
    > tb = CType(e.Item.Cells(1).Controls(0), TextBox)
    >
    > However! A DataGrid I created today will only work if I reference
    > Controls(1) rather than Controls(0):
    >
    > Dim tb As TextBox
    > tb = CType(e.Item.Cells(1).Controls(1), TextBox)
    >
    > Could someone please shed some light on how an attribute can "move
    > around" inside a control, in this case from position 0 to position 1?
    >
    > I don't want them moving around after I'm done. :)
    >
     
    Elton Wang, Aug 3, 2005
    #2
    1. Advertising

  3. Guest

    Re: Simple question: e.Item.Cells(0).Controls­(0)

    Elton Wang wrote:
    > The better way is to use
    >
    > Dim tb As TextBox = CType(e.Item.FindControl(textbox_ID), TextBox)
    >
    > HTH


    Thanks for the reply.

    I think I tried something like that before... I think I had the name in
    quotes though (which may be similar to what you mean, if textbox_ID
    above is a string... man I'm such a newbie at this) Anyhoo I will try
    that in the future.

    FWIW, is there a way to probe the contents of
    e.Item.Cells(0).Controls­() programatically? (I tried QuickWatch -
    there's so much detail, I don't know what I'm looking for.)

    Maybe something like the following psedocode? ...

    for each control in e.item.cells(0).controls()
    display name and type
    next
     
    , Aug 4, 2005
    #3
  4. Sachin Saki Guest

    RE: Simple question: e.Item.Cells(0).Controls­(0)

    "" ने लिखा:

    > I am new at this.. probably not proficient enough to even consider
    > myself a Newbie yet. :)
    >
    > I have a DataGrid with Template columns. After the user edits a field
    > in the DataGrid and presses Update, the UpdateCommand code executes no
    > problem. However...
    >
    > Normally I read the newly edited contents of a cell thusly:
    >
    > Dim tb As TextBox
    > tb = CType(e.Item.Cells(1).Controls(0), TextBox)
    >
    > However! A DataGrid I created today will only work if I reference
    > Controls(1) rather than Controls(0):
    >
    > Dim tb As TextBox
    > tb = CType(e.Item.Cells(1).Controls(1), TextBox)
    >
    > Could someone please shed some light on how an attribute can "move
    > around" inside a control, in this case from position 0 to position 1?
    >
    > I don't want them moving around after I'm done. :)
    >
    > Dim tb As TextBox
    > tb = CType(e.Item.Cells(1).Controls(1), TextBox)

    Should try this think instead of above way
    Dim txt as textbox
    txt = CType(e.item.cell(1).FindControl(""id of textbox"),textbox)

    This method works well for all cases.

    Regards,
    Sachin Saki
    .NET Developer
     
    Sachin Saki, Aug 12, 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. Replies:
    0
    Views:
    531
  2. Joel Finkel

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

    Joel Finkel, Sep 1, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    311
    Joel Finkel
    Sep 1, 2003
  3. Ravichandran Mahalingam

    (TextBox) (e.Item.Cells[2].Controls[0]) - Cast Invalid - Cannot update.

    Ravichandran Mahalingam, Jan 12, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    189
    Ravichandran Mahalingam
    Jan 12, 2004
  4. SoftLion
    Replies:
    2
    Views:
    130
    George
    May 6, 2004
  5. Keith-Earl
    Replies:
    5
    Views:
    187
Loading...

Share This Page