What is the structure hierarchy here?

Discussion in 'ASP .Net Datagrid Control' started by Doru Roman, Feb 14, 2006.

  1. Doru Roman

    Doru Roman Guest

    Hi,

    To update the changes in the grid I use the structure taken from the Help
    examples:

    private void dgCompany_UpdateCommand(object source,
    System.Web.UI.WebControls.DataGridCommandEventArgs e)

    {

    TextBox CompanyBox = (TextBox)e.Item.Cells[2].Controls[0];

    I try to get the hierarchy starting at Item.Cells[2].Controls[0]



    I could not find the Cells and then Controls collections inside the datagrid
    class.

    Can someone explain to me how I can get to the controls in the end, as
    Controls[0] means Textbox, Controls[1] means Checkbox, or at least this is
    what I presume.

    Thanks,

    Doru
     
    Doru Roman, Feb 14, 2006
    #1
    1. Advertising

  2. Doru Roman

    Teemu Keiski Guest

    Hi,

    if you have fixed set of controls there, it's lots easier to use FindControl
    with the ID instead of trying to guess the control hierarchy. The index of
    certain control can vary for example if there's a text (even space will do)
    since such would be converted to a LiteralControl etc

    For example if your control's ID is "CompanyBox":

    TextBox CompanyBox = (TextBox)e.Item.FindControl("CompanyBox");

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke



    "Doru Roman" <> wrote in message
    news:...
    > Hi,
    >
    > To update the changes in the grid I use the structure taken from the Help
    > examples:
    >
    > private void dgCompany_UpdateCommand(object source,
    > System.Web.UI.WebControls.DataGridCommandEventArgs e)
    >
    > {
    >
    > TextBox CompanyBox = (TextBox)e.Item.Cells[2].Controls[0];
    >
    > I try to get the hierarchy starting at Item.Cells[2].Controls[0]
    >
    >
    >
    > I could not find the Cells and then Controls collections inside the
    > datagrid class.
    >
    > Can someone explain to me how I can get to the controls in the end, as
    > Controls[0] means Textbox, Controls[1] means Checkbox, or at least this is
    > what I presume.
    >
    > Thanks,
    >
    > Doru
    >
    >
     
    Teemu Keiski, Feb 14, 2006
    #2
    1. Advertising

  3. Doru Roman

    Doru Roman Guest

    Thanks Teemu for the reply.
    I still don't understand how I can find out the ID of a TextBox inside of a
    DataGrid when it's in the Edit mode.
     
    Doru Roman, Feb 14, 2006
    #3
  4. Doru Roman

    Teemu Keiski Guest

    The ID you'd use is the one given to the TextBox in the Template.

    Say you have

    <EditItemTemplate>
    <asp:TextBox ID="CompanyBox" runat="server" />
    </EditItemTemplate>

    Then this would work

    TextBox CompanyBox = (TextBox)e.Item.FindControl("CompanyBox");

    when running from EditCommand, or ItemCommand etc (e.Item.ItemType is then
    EditItem)

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
    http://blogs.aspadvice.com/joteke



    "Doru Roman" <> wrote in message
    news:...
    > Thanks Teemu for the reply.
    > I still don't understand how I can find out the ID of a TextBox inside of
    > a DataGrid when it's in the Edit mode.
    >
     
    Teemu Keiski, Feb 14, 2006
    #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. Peter Schuller
    Replies:
    23
    Views:
    669
    NickC
    Feb 4, 2008
  2. Marco Alting

    Input form for creating hierarchy structure

    Marco Alting, Aug 14, 2003, in forum: ASP General
    Replies:
    1
    Views:
    117
  3. George Hester

    Try over here likely more to the point here

    George Hester, Sep 30, 2004, in forum: Javascript
    Replies:
    0
    Views:
    119
    George Hester
    Sep 30, 2004
  4. FAQ server
    Replies:
    0
    Views:
    160
    FAQ server
    Aug 10, 2006
  5. FAQ server
    Replies:
    0
    Views:
    137
    FAQ server
    Oct 7, 2006
Loading...

Share This Page