Dropdownlist control problem
-
Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.
-
Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.
Here is a simple example concerning updating derop down list based on selction in another drop down ...
<%@ Page Language="C#" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01
Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<script runat="server">
protected void Button1_Click(object sender, EventArgs e)
{DropDownList1.Items.Clear(); String\[\] ds = {"hi RED","sup RED"}; String\[\] ds1 = { "hi BLUE", "sup BLUE" }; if (DropDownList2.SelectedValue == "RED") { DropDownList1.DataSource = ds; DropDownList1.DataBind(); } if (DropDownList2.SelectedValue == "BLUE") { DropDownList1.DataSource = ds1; DropDownList1.DataBind(); } } </script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
<title>Untitled Page</title>
<style type="text/css">
#UpdatePanel1 { width:300px; height:100px; } </style>
</head>
<body>
<form id="form1" runat="server">
<div style="padding-top: 10px">
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<fieldset>
<legend>UpdatePanel</legend>
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<asp:DropDownList ID="DropDownList2" runat="server">
asp:ListItemRED</asp:ListItem>
asp:ListItemBLUE</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
</fieldset>
</ContentTemplate>
</asp:UpdatePanel>
<br />
</div>
</div>
</form>
</body>
</html> -
Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.
-
Dear Friends, I have three dropdownlist controls. When the page loads, first dropdownlist is filled and the remaining two are empty. When I select some value in First dropdownlist then corresponding values to be populated in Second dropdownlist and same When I select some value in Second dropdownlist then corresponding values to be populated in Third dropdownlist. The problem is, Whatever I select in the First dropdownlist automatically the first item only getting selected. Even If I selected the 5th Item, then also the First Item only getting selected. Please solve my problem. Thanks & Regards, Dileep.
Are you binding the dropdown in page_load event. If so is it within if(!Ispostback) ? I think thats the problem you did not bind the dropdown within if(!Ispostback) I think this may help u............. :)
-
Are you binding the dropdown in page_load event. If so is it within if(!Ispostback) ? I think thats the problem you did not bind the dropdown within if(!Ispostback) I think this may help u............. :)
Your problem could it be like sandympatil said! or maybe you're setting the same dropDownList1.DataValueField in the data source... for example I have as source: -column1----column2 --------------------- -red------------value1 -blue-----------value1 -orange-------value1 -black----------value1 and dropdownlist is dropDownList1.DataTextField = "column1"; dropDownList1.DataValueField = "column2"; look out that. If that's so, the post back always select the first option with 'value1'... Ahh! I recommend you to use ajax CascaddingDropDownList Here!![^]