Copy Code code as follows:
<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_ ');//replace the first column ID with the second column ID
alert (NEWID);
var data = "T1*v1|t2*v2|t3*v3";//background Gets the format of the date, here with a fixed value
var datas = data.split (' | '); /split into multiple groups
for (var i = 0; i < datas.length; i++) {
var D1 = datas[i].split (' * ');//each group is divided into display and real values
$ (NEWID). Append ("<option value=\" "+d1[1]+" \ ">" + d1[0] + "</option>");
alert (D1);
}
Alert (id + "| | |" + value);
});
})
</script>
<body>
<form id= "Form1" runat= "Server" >
<div> to meet two columns, arbitrarily many rows. The background dynamically generates a Drop-down box, and it also needs to be preceded by a cascading level. Using Js+jquery, using server control +ajax is not good, always choose after
<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= "get" onclick= "Buttonget_click"/>
<asp:label id= "Label1" runat= "Server" text= "" ></asp:Label>
</div>
</form>
</body>
Background
protected void Page_Load (object sender, EventArgs e)
{
if (! IsPostBack)
{
}
}
protected void Buttonget_click (object sender, EventArgs e)
{
Gets the value selected by the Ddl_2_1 control selected by JS, displayed on the Label1.
Label1.Text = request["Ddl_2_1"]. ToString ();
}