Template Column

Discussion in 'ASP .Net Datagrid Control' started by VJ, Apr 6, 2004.

  1. VJ

    VJ Guest

    Hi...

    This should be simple I guess.. I have a dropdownbox as a template column in
    my datagrid. When the selected item changes in this dropdown item, I need to
    know the corresponding datarow in the datagrid. How do I determine this?

    VJ
    VJ, Apr 6, 2004
    #1
    1. Advertising

  2. VJ

    Teemu Keiski Guest

    If you handle DDL's SelectedIndexChanged event, you get the DDL instance
    itself from the first parameter of event handler method. Ok, in the control
    hierarchy DDL is inside a TableCell which is inside a DataGridItem (which
    actually inherits from TableRow). Ok, so answer is that you cast the sender
    event argument to DDL and get its parent's parent control something like:

    DataGridItem item=(DataGridItem)((DropDownList)sender).Parent.Parent;

    or straight with NamingContainer property:

    DataGridItem item=(DataGridItem)((DropDownList)sender).NamingContainer;

    The trick here is that DataGridItem can return the index of the DataGridItem
    in Items collection of DataGrid (or DataItem itself if you are databinding)
    which you can use to access the correct data source row. If you are not
    databinding as you probably are not when this is run, you need to somehow
    refetch the data.

    --
    Teemu Keiski
    MCP, Microsoft MVP (ASP.NET), AspInsiders member
    ASP.NET Forum Moderator, AspAlliance Columnist
    http://blogs.aspadvice.com/joteke

    "VJ" <> wrote in message
    news:%238O9aL$...
    Hi...

    This should be simple I guess.. I have a dropdownbox as a template column in
    my datagrid. When the selected item changes in this dropdown item, I need to
    know the corresponding datarow in the datagrid. How do I determine this?

    VJ
    Teemu Keiski, Apr 10, 2004
    #2
    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. Dexter
    Replies:
    1
    Views:
    405
    Eliyahu Goldin
    Jan 18, 2005
  2. Ken Varn
    Replies:
    1
    Views:
    965
    Ken Varn
    Aug 19, 2005
  3. Charleees
    Replies:
    2
    Views:
    8,185
    Eliyahu Goldin
    Jun 20, 2006
  4. Ravichandran Mahalingam

    Bound Column or Template Column (w dAdapater?) in DataGrid

    Ravichandran Mahalingam, Jan 9, 2004, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    204
    Ravichandran Mahalingam
    Jan 9, 2004
  5. Esperanza

    Template column base on another column value

    Esperanza, Feb 18, 2005, in forum: ASP .Net Datagrid Control
    Replies:
    5
    Views:
    166
    Elton Wang
    Feb 21, 2005
Loading...

Share This Page