asp.net中js+jquery添加下拉框值和后台获取示例
更新时间:2014年05月15日 16:45:09 作者:
这篇文章主要介绍了asp.net中js+jquery添加下拉框值和后台获取的具体实现,需要的朋友可以参考下
复制代码 代码如下:
<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_');//把第一列id替换成第二列id
//alert(newid);
var data = "t1*v1|t2*v2|t3*v3";//后台获取的数据格式,这里用固定值了
var datas = data.split('|');//分割成多组
for (var i = 0; i < datas.length; i++) {
var d1 = datas[i].split('*');//每组分割成 显示值和真实值
$(newid).append("<option value=\""+d1[1]+"\">" + d1[0] + "</option>");
//alert(d1);
}
// alert(id + "|||" + value);
});
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>为了满足两列,任意多行。后台动态生成下拉框,还要前后列联级的需求。使用js+jquery,用服务器控件+Ajax也不行,老是选择之后就
<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="获取" onclick="ButtonGet_Click" />
<asp:Label ID="Label1" runat="server" Text=""></asp:Label>
</div>
</form>
</body>
</html>
//后台
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
}
}
protected void ButtonGet_Click(object sender, EventArgs e)
{
///获取通过js加选择的 ddl_2_1 控件选中的值,显示在Label1上。
Label1.Text = Request["ddl_2_1"].ToString();
}
相关文章
asp.net下用Aspose.Words for .NET动态生成word文档中的数据表格的方法
导出word 文档,要求这个文档的格式不是固定的,用户可以随便的调整,导出内容中的数据表格列是动态的,例如要求导出姓名和性别,你就要导出这两列的数据,而且这个文档不是导出来之后再调整而是导出来后已经是调整过了的。2010-04-04
document.getElementsByName和document.getElementById 在IE与FF中不同
今天在<asp:radiobuttonlist/>中使用教本的的时候才注意到原来 document.getElementsByName 、document.getElementById 在IE与FF中有着不同实现。2008-12-12
asp.net利用NamingContainer属性获取GridView行号的方法
在最近的一个项目中,用到在GridView模板列中添加有DropDownList控件,并开启其AutoPostback属性。当发生SelectedIndexChanged事件时,想同时获取其所在的行号,从而获取相应的行信息。2013-07-07
ASP.NET下上传图片到数据库,并且读出图片的代码(详细版)
上传图片到数据库,从数据库的创建到数据库中图片的现实都给出了具体的代码,因为asp.net版本的问题,大家可能需要稍微修改下。2010-07-07
linq to sql中,如何解决多条件查询问题,答案,用表达式树!
有个小项目中,用到了linq to sql,既然这样,想必需要做多条件组合查询了,虽然我对表达式树的研究也只是寥寥地,但除此方法,似乎别无他法,只好硬着头皮研究一下.2011-08-08


最新评论