asp.net js+jquery add drop-down box value and background Get sample _ Practical Tips

Source: Internet
Author: User
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 ();
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.