Drop down list on each GridView row

Discussion in 'ASP .Net' started by McGeeky, Sep 22, 2007.

  1. McGeeky

    McGeeky Guest

    Hi. I have a read only GridView. For each row I want to display a drop down
    list which contains a list of actions the user can select from for that
    particular row. E.g. "view details". When they select an action in the drop
    down list I want to do a post back. How will I know which row they made the
    selection in?

    Is there a way to embed the row Id in the drop down list so it gets sent
    back to the server?

    Thanks
     
    McGeeky, Sep 22, 2007
    #1
    1. Advertising

  2. McGeeky

    Teemu Keiski Guest

    Hi,

    you don't need the row ID. Instead handle DropDownList's
    SelectedIndexChanged event and in that get reference to the DropDownList
    raising the event, you'd get that via sender argument (first argument to the
    event handling method)

    [VB.NET]
    Dim ddl As DropDownList = CType(sender, DropDownList)

    [C#]
    DropDownList ddl = (DropDownList)sender;

    Then trick is to know how databound controls work. The GridViewRow is naming
    container of your DropDownList

    [VB.NET]
    Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)

    [C#]
    GridViewRow row = (GridViewRow)ddl.NamingContainer;

    I've explained some background for this type of scenarios:

    Understanding the naming container hierarchy of ASP.NET databound controls
    http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx

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



    "McGeeky" <> wrote in message
    news:%23Z%23VDFQ$...
    > Hi. I have a read only GridView. For each row I want to display a drop
    > down list which contains a list of actions the user can select from for
    > that particular row. E.g. "view details". When they select an action in
    > the drop down list I want to do a post back. How will I know which row
    > they made the selection in?
    >
    > Is there a way to embed the row Id in the drop down list so it gets sent
    > back to the server?
    >
    > Thanks
    >
     
    Teemu Keiski, Sep 23, 2007
    #2
    1. Advertising

  3. McGeeky

    McGeeky Guest

    Cool. Thanks so much for that!!

    "Teemu Keiski" <> wrote in message
    news:uGt2I6a$...
    > Hi,
    >
    > you don't need the row ID. Instead handle DropDownList's
    > SelectedIndexChanged event and in that get reference to the DropDownList
    > raising the event, you'd get that via sender argument (first argument to
    > the event handling method)
    >
    > [VB.NET]
    > Dim ddl As DropDownList = CType(sender, DropDownList)
    >
    > [C#]
    > DropDownList ddl = (DropDownList)sender;
    >
    > Then trick is to know how databound controls work. The GridViewRow is
    > naming container of your DropDownList
    >
    > [VB.NET]
    > Dim row As GridViewRow = CType(ddl.NamingContainer, GridViewRow)
    >
    > [C#]
    > GridViewRow row = (GridViewRow)ddl.NamingContainer;
    >
    > I've explained some background for this type of scenarios:
    >
    > Understanding the naming container hierarchy of ASP.NET databound controls
    > http://aspadvice.com/blogs/joteke/a...-hierarchy-of-ASP.NET-databound-controls.aspx
    >
    > --
    > Teemu Keiski
    > AspInsider, ASP.NET MVP
    > http://blogs.aspadvice.com/joteke
    > http://teemukeiski.net
    >
    >
    >
    > "McGeeky" <> wrote in message
    > news:%23Z%23VDFQ$...
    >> Hi. I have a read only GridView. For each row I want to display a drop
    >> down list which contains a list of actions the user can select from for
    >> that particular row. E.g. "view details". When they select an action in
    >> the drop down list I want to do a post back. How will I know which row
    >> they made the selection in?
    >>
    >> Is there a way to embed the row Id in the drop down list so it gets sent
    >> back to the server?
    >>
    >> Thanks
    >>

    >
    >
     
    McGeeky, Sep 23, 2007
    #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. SirPoonga
    Replies:
    2
    Views:
    815
    Ben Strackany
    Jan 7, 2005
  2. weiwei
    Replies:
    0
    Views:
    1,070
    weiwei
    Jan 5, 2007
  3. msimmons
    Replies:
    0
    Views:
    545
    msimmons
    Jul 16, 2009
  4. D
    Replies:
    0
    Views:
    252
  5. Replies:
    5
    Views:
    315
Loading...

Share This Page