Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Dependent DropDownLists

Reply
Thread Tools

Dependent DropDownLists

 
 
stephen
Guest
Posts: n/a
 
      08-31-2004
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.
 
Reply With Quote
 
 
 
 
Naveen
Guest
Posts: n/a
 
      09-05-2004
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.
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
non-dependent vs. dependent template names puzzlecracker C++ 1 08-07-2008 07:42 AM
Multiple dependent dropdownlists in whidbey Geoff Taylor ASP .Net Building Controls 1 08-06-2004 07:21 PM
Dependent dropdownlists without an auto postback Chester ASP .Net Web Controls 1 07-30-2004 08:19 PM
Positioning in dropdownlists Peter J. Hunter ASP .Net 0 01-14-2004 04:13 AM
parent child dropdownlists acting oddly Craig Buchanan ASP .Net 1 06-27-2003 06:10 PM



Advertisments