Dependent DropDownLists

Discussion in 'ASP .Net Datagrid Control' started by stephen, Aug 31, 2004.

  1. stephen

    stephen Guest

    I am having a problem with my datagrid. I have 2 edit
    columns containing DropDownLists, one dependent on
    another. Both lists are being populated from a sql
    database.

    Essentially, the first DropDownList contains a list of
    colors (i.e. Red, Blue, Green, etc) with the second
    DropDownList containing different shades available for
    the selected color (i.e. if Red is selected in the first
    DropDownList then the second DropDownList should contain
    Scarlet, Blood, Bright, Dark, etc).

    I cannot find a way to populate the second DropDownList
    each time the user changes their selection in the first
    DropDownList.
    stephen, Aug 31, 2004
    #1
    1. Advertising

  2. stephen

    Naveen Guest

    Hi Stephen,

    You can implemented this functionality like this :

    1. Add an handler for OnSelectedIndexChanged event of your First Drop Down
    List.
    i.e OnColorChange(ByVal sender As Object, ByVal e As EventArgs)
    2. In the Event Handler :
    'Get the First DropDown
    Dim colorDropDown As DropDownList = CType(sender, DropDownList)
    Dim selectedColorID As String = colorDropDown.SelectedItem.Value

    'Get the Second DropDown
    Dim item As DataGridItem = CType(colorDropDown.Parent.Parent, DataGridItem)
    Dim ShadesDropDown As DropDownList = CType(item.FindControl("ddlShades"),
    DropDownList)

    'Get the Data from DB or Session to populate Second DropDown based on the
    Item selected in First Dropdown

    dtShades = CType(Session("shades"), DataTable)
    dvShades = dtShades.DefaultView
    Me.dvShades.RowFilter = String.Empty
    If Not selectedColorID = "-1" Then
    Me.dvShades.RowFilter = "ColorID ='" & selectedColorID & "'"
    End If

    With ShadesDropDown
    .DataSource = dvShades
    .DataValueField = "ShadeId"
    .DataTextField = "ShadeName"
    .DataBind()
    End With

    Hope It helps :)


    "stephen" wrote:

    > I am having a problem with my datagrid. I have 2 edit
    > columns containing DropDownLists, one dependent on
    > another. Both lists are being populated from a sql
    > database.
    >
    > Essentially, the first DropDownList contains a list of
    > colors (i.e. Red, Blue, Green, etc) with the second
    > DropDownList containing different shades available for
    > the selected color (i.e. if Red is selected in the first
    > DropDownList then the second DropDownList should contain
    > Scarlet, Blood, Bright, Dark, etc).
    >
    > I cannot find a way to populate the second DropDownList
    > each time the user changes their selection in the first
    > DropDownList.
    >
    Naveen, Sep 5, 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. Peter J. Hunter

    Positioning in dropdownlists

    Peter J. Hunter, Jan 14, 2004, in forum: ASP .Net
    Replies:
    0
    Views:
    517
    Peter J. Hunter
    Jan 14, 2004
  2. Craig Buchanan

    parent child dropdownlists acting oddly

    Craig Buchanan, Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    465
    Craig Buchanan
    Jun 27, 2003
  3. puzzlecracker
    Replies:
    1
    Views:
    519
    James Kanze
    Aug 7, 2008
  4. Geoff Taylor

    Multiple dependent dropdownlists in whidbey

    Geoff Taylor, Aug 6, 2004, in forum: ASP .Net Building Controls
    Replies:
    1
    Views:
    128
    Chandra Sekhar
    Aug 6, 2004
  5. Chester

    Dependent dropdownlists without an auto postback

    Chester, Jul 30, 2004, in forum: ASP .Net Web Controls
    Replies:
    1
    Views:
    221
Loading...

Share This Page