problem with dropdownlist inside of datagrid

Discussion in 'ASP .Net' started by tfsmag@gmail.com, Jun 6, 2005.

  1. Guest

    Hello,

    I'm still relatively new to asp.net and i'm having troubles with a
    dropdownlist in a datagrid. Here is the code for the dropdownlist

    ---------------------------------
    <asp:DropDownList Runat="server"
    OnSelectedIndexChanged="ddlSelectionChanged" SelectedValue='<%#
    DataBinder.Eval(Container.DataItem, "ACTIVE")%>' ID="DropDown"
    AutoPostBack="True">
    <asp:ListItem Value="1">Enabled</asp:ListItem>
    <asp:ListItem Value="0">Disabled</asp:ListItem>
    <asp:ListItem Value="2">Deleted</asp:ListItem>
    </asp:DropDownList>
    ---------------------------------

    This renders fine, and the proper index is selected when the page comes
    up, the difficulty i'm having is capturing the row's unique id field to
    update the database when they select a new index and fire the
    "ddlSelectionChanged".

    Here is the codebehind code for the ddlSelectionChanged event

    ---------------------------
    Protected Sub ddlSelectionChanged(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles DropDown.SelectedIndexChanged
    Dim ddl As DropDownList
    ddl = CType(sender, DropDownList)
    Dim user_id as integer = (??? this is where i can't figure out
    how to get the row id)
    End Sub
    ---------------------------

    The event does fire, I made sure of that by using a label and wrote
    something to the label at the end of the event.

    Any help here would be greatly appreciated as I am about ready to pull
    my hair out!

    Thanks,
    Jeff T.
     
    , Jun 6, 2005
    #1
    1. Advertising

  2. Teemu Keiski Guest

    Hi,

    Despite that event is fired by the DDL, DDL is still located in the DataGrid
    and especially in its control hierarchy.Therefore you are interested in the
    DataGridItem which contains the DDL. The DataGridItem could be get using:

    Dim dgi As DataGridItem = CType(ddl.Parent.Parent,DataGridItem)

    (or ddl.NamingContainer instead of ddl.Parent.Parent)

    If you have assigned the ID into DataKeys of Datagrid (means DataKeyField is
    set), you could get it from the collection using

    Dim user_id As Integer=CInt(dgInstance.DataKeys(dgi.ItemIndex))

    And again if the ID is stored into a control or a cell, you could access
    them also via the DatagridItem.

    --
    Teemu Keiski
    ASP.NET MVP, AspInsider
    Finland, EU
     
    Teemu Keiski, Jun 6, 2005
    #2
    1. Advertising

  3. tfsmag Guest

    that worked! holy cow, if you were here i'd take you out for a beer :p

    thanks again!
     
    tfsmag, Jun 6, 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. Dominic
    Replies:
    2
    Views:
    738
    Saravana
    Jul 4, 2003
  2. =?Utf-8?B?QXVkcmV5?=
    Replies:
    2
    Views:
    417
    =?Utf-8?B?QXVkcmV5?=
    Feb 6, 2004
  3. Luis Esteban Valencia
    Replies:
    0
    Views:
    553
    Luis Esteban Valencia
    Mar 23, 2005
  4. Michael Kolias

    DropDownList problems inside a datagrid

    Michael Kolias, Jun 10, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    492
    Michael Kolias
    Jun 10, 2005
  5. keithb
    Replies:
    1
    Views:
    12,174
    shauns1
    Nov 1, 2006
Loading...

Share This Page