Showing posts with label programmatically. Show all posts
Showing posts with label programmatically. Show all posts

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.

CascadingDropDown setting SelectedValue programmatically doesnt work

Hi

I have a page which has four dropdowns "linked" together via CascadingDropDown Extenders.

The page works fine, except that I sometimes want the dropdowns to be pre-populated and specific items selected programmatically.

e.g.

1cddlMakes.SelectedValue = cmk.Vehicle.Make.ID2cddlModels.SelectedValue = cmk.Vehicle.Model.ID3cddlTypes.SelectedValue = cmk.Vehicle.Type.ID4cddlEngines.SelectedValue = cmk.Vehicle.Engine.ID

The first 2 dropdowns load and display the correct selected value, but the other two dropdowns SelectedValues don't get set and stay on the "Please Select..." option.

Any ideas?

Using the sample page, I have no issue programmatically setting any of the 3 cascading drop down extenders' selected value. Are you setting the extenders or the controls?
12 CascadingDropDown1.SelectedValue ="Acura";3 CascadingDropDown2.SelectedValue ="Integra";4 CascadingDropDown3.SelectedValue ="Green";