如何获取Select表单中的值,我用request.Form("select111"),取不出来

pandengzhe 2007-10-26 11:27:26
asp.net,c#
如何获取Select表单中的值,我用request.Form("select111"),取不出来
...全文
1602 21 打赏 收藏 转发到动态 举报
写回复
用AI写文章
21 条回复
切换为时间正序
请发表友善的回复…
发表回复
蝶恋花雨 2012-06-05
  • 打赏
  • 举报
回复
public string GetStr()
{
StringBuilder sBulid = new StringBuilder();
sBulid.Append(@"<select id=""select18"" name=""select"">
<option value=""男"">男 </option >
<option value=""女"">女 </option > //去掉一个也没问题。
</select > ");
return sBulid.ToString();
}
protected void test_Click(object sender, EventArgs e)
{
if (Request.Form["select"] != null)
{
string s = Request.Form["select"];
Response.Write(s);
}
}

已经测试没问题。
前台<%=GetStr()%>
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]

System.Collections.Specialized.NameValueCollection nvc=Request.Form;
int i=nvc.Count;
---------------------------------------
取得Form,我要select中的option 的COunt
[/Quote]

给你的select加上id="select1" runat="server"
int i=select1.Items.Count;
取值用select1.Value
蝶恋花雨 2012-06-05
  • 打赏
  • 举报
回复
后台C#代码获取html控件的值使用的Request.Form["name"]
"Name"是html的name,如果有相同name的控件,可以用逗号分割

sBulid.Append(@"<select id=""select18""> 里面加上name 就能取得了。
蝶恋花雨 2012-06-05
  • 打赏
  • 举报
回复
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function test()
{
var el = document.getElementById("sel");
document.getElementById("hitest").value = el.options[el.selectedIndex].value;
alert(document.getElementById("hitest").value);
}

</script>
</head>
<body>
<form id="form1" runat="server">
<select id="sel" onchange="test()" Style="margin:-2px;width:40px;background-color: #CCCCCC;" size="1" >
<option value="男"> 男 </option >
<option value="女">女 </option >
</select >
<input type="hidden" id="hitest" runat="server"/> </form>
</body>
</html>


页面上放置一个隐藏域 input type=hidden

在后台直接hitest。value

qingyou_jun 2012-06-05
  • 打赏
  • 举报
回复
public string GetStr()
{
StringBuilder sBulid = new StringBuilder();
sBulid.Append(@"<select id=""select18"">
<option value=""男"">男 </option >
<option value=""女"">女 </option >
</select > ");
return sBulid.ToString();
}
protected void Page_Load(object sender, EventArgs e)
{

}

protected void Button1_Click(object sender, EventArgs e)
{
if (Request.Form["select18"] != null)
{
string s = Request.Form["select18"];
Response.Write(s);
}
}

如果是一个select呢,怎么获取选中的值?上面办法选不到。
kyouken2007 2007-10-26
  • 打赏
  • 举报
回复
1.Request.Form["select111"]


2.如何在C#中实现asp中如下的功能:

Request.Form(element).count

C#中Request.Form[element]是一个字符串

有没有替代方法?
---------------------------------------
System.Collections.Specialized.NameValueCollection nvc=Request.Form;
int i=nvc.Count;
hy_lihuan 2007-10-26
  • 打赏
  • 举报
回复
使用服务器控件算了。
QQ30871740 2007-10-26
  • 打赏
  • 举报
回复
把你的()换成[]试下,可能是括号的问题
pineapplemi 2007-10-26
  • 打赏
  • 举报
回复
Request.Form["select111"] select111是 name
rifhgd 2007-10-26
  • 打赏
  • 举报
回复
Request.Form["select111"]
pandengzhe 2007-10-26
  • 打赏
  • 举报
回复
<select name="select18" Style="margin:-2px;width:40px;background-color: #CCCCCC;" size="1">
<option>男</option>
<option>女</option>
 
</select>

要把男、女都提取出来
pandengzhe 2007-10-26
  • 打赏
  • 举报
回复
如何在C#中实现asp中如下的功能:

Request.Form(element).count

C#中Request.Form[element]是一个字符串

有没有替代方法?
bumm 2007-10-26
  • 打赏
  • 举报
回复
Request.Form("select111"),检查select111名称是否正确。
stubborn_99 2007-10-26
  • 打赏
  • 举报
回复
记得给你的选项加value数据
<select id="select18" Style="margin:-2px;width:40px;background-color: #CCCCCC;" size="1" >
<option value="">男 </option >
<option value="">女 </option >
 
</select >

cs页面
if (HttpContext.Current.Request.Form["select18"] != null)
{
string[] str= HttpContext.Current.Request.Form["select18"].ToString().Split(',');
throw new Exception(str.Length.ToString());
}
else
Response.Write("没有数据");
honey52570 2007-10-26
  • 打赏
  • 举报
回复
runat server就很好解决了吧,没必要瞎折腾
phtiger 2007-10-26
  • 打赏
  • 举报
回复
你這種使用服務器控件不是更好
wj198555 2007-10-26
  • 打赏
  • 举报
回复
up
kyouken2007 2007-10-26
  • 打赏
  • 举报
回复
不好意思
理解错了

让他runat=“server”不行吗?
int i=this.Select1.Items.Count;
pandengzhe 2007-10-26
  • 打赏
  • 举报
回复
用javascript,C#本身没有?
pandengzhe 2007-10-26
  • 打赏
  • 举报
回复
System.Collections.Specialized.NameValueCollection nvc=Request.Form;
int i=nvc.Count;
---------------------------------------
取得Form,我要select中的option 的COunt
加载更多回复(1)

62,046

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧