我有一个<asp:DropDownList/> 已经绑定了数据 所以每次加载的时候会有选项出现
然后有一个<input type="button" onclick="function()" /> 单击执行脚本后会往DropDownList里面添加进去一个新的项还有一个按钮是"确定" 当我从DropDownList里面选择一个项后单击该“确定”按钮要提取选中的值
问题出来了???
原先绑定的数据项可以成功提取但是我新添加进去的项,又了好多方法还是获取不了(总是得到第一项)
这是怎么回事呢? 求解决方法啊谢谢
然后有一个<input type="button" onclick="function()" /> 单击执行脚本后会往DropDownList里面添加进去一个新的项还有一个按钮是"确定" 当我从DropDownList里面选择一个项后单击该“确定”按钮要提取选中的值
问题出来了???
原先绑定的数据项可以成功提取但是我新添加进去的项,又了好多方法还是获取不了(总是得到第一项)
这是怎么回事呢? 求解决方法啊谢谢
Request.Form[DropDownList1.UniqueID]得到选择的
function inputFileName() {
var fileName = prompt("输入新建的文件夹名", "");
if (fileName != null) {
var fileNameList = document.getElementById("ctl00_cphPostback_fileNameList");
var option = document.createElement('OPTION');
option.text = fileName;
fileNameList.options.add(option);
}
}后台 protected void Unnamed3_Click(object sender, EventArgs e)
{
string selectFileName = fileNameList.SelectedItem.Text;
//selectFileName 选择新建的项时就会出现选择绑定数据第一项的的现象
}回复一楼 添加时页面没刷新
不懂 求详解 谢谢
因为viewstate 。所以在后台获取不到 。
我是在dropdownlist 选中时 再赋值给个隐藏域 。
用这个隐藏域获得值 。
不管是怎么添加的
改成string selectFileName = Request.Form[fileNameList.UniqueID];
后 选择事先绑定的数据又出现问题问题就颠倒了 现在选择新添加的有用 而选择绑定的就没用了
郁闷啊
你是怎么测试的?
拷贝下面的代码测试<%@ Page Language="C#" EnableEventValidation="false" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server"> protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
DropDownList1.DataSource = new String[] { "A", "B" };
DropDownList1.DataBind();
}
} protected void Button1_Click(object sender, EventArgs e)
{
Response.Write(Request.Form[DropDownList1.UniqueID]);
}
</script><html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function Add() {
d = document.getElementById("<%=DropDownList1.ClientID %>");
for (i = 0; i < 6; i++) {
d.options[d.options.length] = new Option(i, i);
}
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>
<input type="button" value="添加" onclick="Add()" />
<asp:Button ID="Button1" runat="server" Text="得到选中的" onclick="Button1_Click" />
</form>
</body>
</html>