PDA

View Full Version : Master Detail Dropdownlist and ajax



dehghanimeh
پنج شنبه 16 شهریور 1391, 01:34 صبح
با سلام
من یه Dropdownlist دارم که اطلاعات آن ( استان ها ی کشور ) از بانک اطلاعاتی خوانده میشه
حالا وقتی کاربر یکی از استانها را انتخاب کرد شهرستانهای اون از بانک اطلاعاتی خونده بشه
و در Dropdownlist بارگزاری بشه
چند راه حل وجود داره ؟اگر لطف کنید یه مثال معرفی کنید ممنون می شم
با تشکر

meisam12
پنج شنبه 16 شهریور 1391, 01:53 صبح
سلام
از سورس کد زیر استفاده کن

<%@ Page Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script language="javascript">
function MyApp(sender){
var lbMatch = false;
var loDDL2 = document.form1.DDL2;
for(var i=0; i< loDDL2.length-1; i++){
lbMatch = sender.value==loDDL2.options[i].value;
lsSelected = lbMatch ? "<=SELECTED" : "";
if(lbMatch)
loDDL2.selectedIndex = sender.selectedIndex;
alert("DDL1:"+sender.value+ " DDL2:"+loDDL2.options[i].value + lsSelected );
}
}
</script>
<script runat="server">
protected void Page_Load(object sender, EventArgs e) {
DDL1.Attributes.Add("OnChange", "MyApp(this)");
}
</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="DDL1" runat="server" Width="43px">
<asp:ListItem Value="1"></asp:ListItem>
<asp:ListItem Value="2"></asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem Value="4"></asp:ListItem>
</asp:DropDownList>
<asp:DropDownList ID="DDL2" runat="server">
<asp:ListItem>1</asp:ListItem>
<asp:ListItem>2</asp:ListItem>
<asp:ListItem>3</asp:ListItem>
<asp:ListItem>4</asp:ListItem>
<asp:ListItem></asp:ListItem>
</asp:DropDownList></div>
</form>
</body>
</html>