Find a column by name

Discussion in 'ASP .Net Datagrid Control' started by Eagle, May 11, 2005.

  1. Eagle

    Eagle Guest

    How do I find a column in a grid by the name of the column? I find I'm
    constantly having to change the cell numbers because the order of the
    columns in the grid changes. Thanks.
     
    Eagle, May 11, 2005
    #1
    1. Advertising

  2. Eagle

    Teemu Keiski Guest

    Hi,

    columns do not have a name, if you mean a Datagrid. Simple way is to use
    Labels or LiteralControls in the columns (in a template), which you could
    locate with FindControl and set/get text properties respectively. That way
    you wouldn't depend on the order of the columns.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU

    "Eagle" <> wrote in message
    news:es2$...
    > How do I find a column in a grid by the name of the column? I find I'm
    > constantly having to change the cell numbers because the order of the
    > columns in the grid changes. Thanks.
    >
    >
     
    Teemu Keiski, May 13, 2005
    #2
    1. Advertising

  3. Eagle

    Eagle Guest

    Thanks! I did a
    Dim MyValue2 as String = CType(e.Item.FindControl("Year"), TextBox).Text

    So I can now find the control and get the value of the control, but how do I
    find its CellIndex and Control Index number? I have to pass the indexes
    into another procedure that creates a dropdownlist:
    Dim ddl As DropDownList =
    CType(e.Item.Cells(CellIndex).Controls(ControlIndex), DropDownList)





    "Teemu Keiski" <> wrote in message
    news:...
    > Hi,
    >
    > columns do not have a name, if you mean a Datagrid. Simple way is to use
    > Labels or LiteralControls in the columns (in a template), which you could
    > locate with FindControl and set/get text properties respectively. That way
    > you wouldn't depend on the order of the columns.
    >
    > --
    > Teemu Keiski
    > ASP.NET MVP, AspInsider
    > Finland, EU
    >
    > "Eagle" <> wrote in message
    > news:es2$...
    > > How do I find a column in a grid by the name of the column? I find I'm
    > > constantly having to change the cell numbers because the order of the
    > > columns in the grid changes. Thanks.
    > >
    > >

    >
    >
     
    Eagle, May 13, 2005
    #3
    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. DBLWizard
    Replies:
    1
    Views:
    8,161
    Eliyahu Goldin
    Jul 19, 2005
  2. Rahul
    Replies:
    5
    Views:
    165
    J. Gleixner
    Mar 19, 2007
  3. Tim Chase
    Replies:
    7
    Views:
    303
    Dennis Lee Bieber
    Jul 20, 2012
  4. Peter Otten
    Replies:
    0
    Views:
    216
    Peter Otten
    Jul 19, 2012
  5. Tim Chase
    Replies:
    0
    Views:
    157
    Tim Chase
    Jul 19, 2012
Loading...

Share This Page