Saturday, March 24, 2012

CascadingDropDown with two items containing the same value

I'd like to create a cascading drop down control with two list items that have the same value and also be able to programmatically populate the drop down via the selected item's text. I haven't seen anything like this and I can't see a way to do it.

In the sample pages I've changed the CarService.xml file as follows:

1 <make name="Audi" value="Audi (value)">2 <model name="A4" value="A4 (value)">3 <color name="Azure" value="Azure (value)" />4 <color name="Light Azure" value="Light Azure (value)" />5 <color name="Dark Azure" value="Dark Azure (value)" />6 <color name="Test Azure" value="Dark Azure (value)" />7 </model>

...adding the "Test Azure" color node with the same value as "Dark Azure". Note that when you select "Dark Azure" on the page, then select "Test Azure", theDropDownList3_SelectedIndexChanged event doesn't fire.

Does anyone know how to do this?

Hi,

I tried it, it worked fine.

I add the line

<color name="Test Azure" value="Dark Azure (value)" /> to the xml file as you described, and didn't modify a line of code.
 

I tried it again and still no dice. It may not be possible:

I created the following page to test regular asp.net...

<%@. Page Language="C#" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void ddlTest_SelectedIndexChanged(object sender, EventArgs e) { Label1.Text = String.Format("{0} - {1}", ddlTest.SelectedIndex, ddlTest.SelectedValue); }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>Untitled Page</title></head><body> <form id="form1" runat="server"> <div> <asp:DropDownList ID="ddlTest" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlTest_SelectedIndexChanged"> <asp:ListItem Text="Apple" Value="Red"></asp:ListItem> <asp:ListItem Text="Banana" Value="Yellow"></asp:ListItem> <asp:ListItem Text="Apple Again" Value="Red"></asp:ListItem> </asp:DropDownList> <asp:Label ID="Label1" runat="server"></asp:Label> </div> </form></body></html>

Notice that selecting "Apple Again" will autopostback with "Apple" selected. I'll look for another solution.


That's because "apple" and "apple again" have the same value.

No comments:

Post a Comment