asp. js+jquery adds a drop down box value and a background fetch example to asp. net

  • 2020-12-20 03:32:47
  • OfStack

 
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head runat="server"> 
<title></title> 
<script src="Scripts/jquery-1.4.1.js" type="text/javascript"></script> 
<script type="text/javascript"> 
$(function () { 
$(".cg2").change(function () { 
var id = $(this).attr("id"); 
var value = $(this).val(); 
var newid = '#'+id.replace('_1_', '_2_');// The first 1 column id Replace the first 2 column id 
//alert(newid); 
var data = "t1*v1|t2*v2|t3*v3";// The format of the data that we're getting in the background, we're using fixed values here  
var datas = data.split('|');// Divide into groups  
for (var i = 0; i < datas.length; i++) { 
var d1 = datas[i].split('*');// Divide each group into two parts   Displays values and true values  
$(newid).append("<option value=\""+d1[1]+"\">" + d1[0] + "</option>"); 
//alert(d1); 
} 
// alert(id + "|||" + value); 
}); 
}) 

</script> 
</head> 
<body> 
<form id="form1" runat="server"> 
<div> In order to satisfy two columns, any number of rows. Background dynamic generation of drop-down box, but also before and after the cascading requirements. use js+jquery , using a server control +Ajax No, not always after the choice  
<asp:DropDownList ID="ddl_1_1" CssClass="cg2" runat="server"> 
<asp:ListItem Text="txt1" Value="val1"></asp:ListItem> 
<asp:ListItem Text="txt1" Value="val1"></asp:ListItem> 
<asp:ListItem Text="txt1" Value="val1"></asp:ListItem> 
</asp:DropDownList> 
<asp:DropDownList ID="ddl_2_1" runat="server"> 
</asp:DropDownList><br/> 
<asp:DropDownList ID="ddl_1_2" CssClass="cg2" runat="server"> 
<asp:ListItem Text="txt2" Value="val2"></asp:ListItem> 
<asp:ListItem Text="txt2" Value="val2"></asp:ListItem> 
<asp:ListItem Text="txt2" Value="val2"></asp:ListItem> 
</asp:DropDownList> 
<asp:DropDownList ID="ddl_2_2" runat="server"> 
</asp:DropDownList><br/> 
<asp:Button ID="ButtonGet" runat="server" Text=" To obtain " onclick="ButtonGet_Click" /> 
<asp:Label ID="Label1" runat="server" Text=""></asp:Label> 
</div> 
</form> 
</body> 
</html> 

// The background  

protected void Page_Load(object sender, EventArgs e) 
{ 
if (!IsPostBack) 
{ 

} 
} 

protected void ButtonGet_Click(object sender, EventArgs e) 
{ 
/// To get through js And choose  ddl_2_1  Control displays the selected value in Label1 On.  
Label1.Text = Request["ddl_2_1"].ToString(); 
} 

Related articles: