selectdvalue selecteditem.value selecteditem.text 好混淆,究竟是什么东西呢? selectdvalue selecteditem.value selecteditem.text 好混淆,究竟是什么东西呢? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 DropDownList.SelectedItem.Text 和 DropDownList.SelectedValue <%@ Page Language="C#" %><!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 Button1_Click(object sender, EventArgs e) { MessageOne.Text = "来自" + DropDownListCity.SelectedItem.Text +"的" + TextBoxName.Text ; //DropDownListCity.SelectedItem.Text 的内容是 <asp:ListItem Value ="GaoLaoZhuang">高老庄</asp:ListItem>中间的"高老庄" MessageTwo.Text = "来自" + DropDownListCity.SelectedValue +"的" + TextBoxName.Text; //DropDownListCity.SelectedValue 是<asp:ListItem Value ="GaoLaoZhuang">中的Value中指定的值. MessageThree.Text = "来自" + DropDownListCity.SelectedItem.Value + "的" + TextBoxName.Text; //DropDownList.SelectedItem.Value 和 DropDownList.SelectedValue 是一样的. }</script><html xmlns="http://www.w3.org/1999/xhtml" ><head runat="server"> <title>ASP.NET学习001</title></head><body> <form id="form1" runat="server"> <asp:TextBox ID="TextBoxName" runat="server"/> <asp:DropDownList ID="DropDownListCity" runat="server"> <asp:ListItem Value ="GaoLaoZhuang">高老庄</asp:ListItem> <asp:ListItem Value ="TianPengYuanShuaiFu">天蓬元帅府</asp:ListItem> </asp:DropDownList> <asp:Button ID="Button1" runat="server" Text="确定" /> <br /> <asp:Label ID="MessageOne" runat="server" /> <br /> <asp:Label ID="MessageTwo" runat="server" /> <br /> <asp:Label ID="MessageThree" runat="server" /> </form></body></html> SelectedItem.Value和SelectedValue功能差不多,还是有区别的,如果没有一个List Item被选中,那么SelectedItem.Value将会报错,SelectedValue的值为空字符串。 selectdvalue貌似是JS取的? 比如一个DropDownList 属性 说明 Text 列表中显示的文本。 Value 与某个项关联的值。设置此属性可使您将该值与特定的项关联而不显示该值。 Selected 布尔值,指示该项是否被选定。 DropDownList 控件的 Items 是一个标准集合,您可以向它添加项对象。selecteditem就是指你选定的项。selecteditem.text 就是选定项的文本。selecteditem.value 就是选定项的关联值。例如我们可以用text 显示人名,而value值绑定人员的id。selectedvaule就是直接指你选定的关联值。(vs2005中才有,vs2003中没有) 母版页乱码 现成的操作数据库的dll文件会有connection不关闭的情况吗? repeater数据导出到Excel 关于javaScript 里正则表达式的请教 datagrid取值问题 这个网站的双语切换是如果做出来的啊 DESIGNTIMEDRAGDROP 是什麽意思? vss2005如何实现 本地编辑 远程运行 session_end问题 请教高手!!在IIS上如何建立多个独立的ASP应用程序;在同一台机器上,独立ASP应用程序究竟指什么??? 求准确答案! 正则获取www.qq.com/nba.qq.com
<%@ Page Language="C#" %>
<!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 Button1_Click(object sender, EventArgs e)
{
MessageOne.Text = "来自" + DropDownListCity.SelectedItem.Text +"的" + TextBoxName.Text ;
//DropDownListCity.SelectedItem.Text 的内容是 <asp:ListItem Value ="GaoLaoZhuang">高老庄</asp:ListItem>中间的"高老庄"
MessageTwo.Text = "来自" + DropDownListCity.SelectedValue +"的" + TextBoxName.Text;
//DropDownListCity.SelectedValue 是<asp:ListItem Value ="GaoLaoZhuang">中的Value中指定的值. MessageThree.Text = "来自" + DropDownListCity.SelectedItem.Value + "的" + TextBoxName.Text;
//DropDownList.SelectedItem.Value 和 DropDownList.SelectedValue 是一样的.
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>ASP.NET学习001</title>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBoxName" runat="server"/>
<asp:DropDownList ID="DropDownListCity" runat="server">
<asp:ListItem Value ="GaoLaoZhuang">高老庄</asp:ListItem>
<asp:ListItem Value ="TianPengYuanShuaiFu">天蓬元帅府</asp:ListItem>
</asp:DropDownList>
<asp:Button ID="Button1" runat="server" Text="确定" />
<br />
<asp:Label ID="MessageOne" runat="server" />
<br />
<asp:Label ID="MessageTwo" runat="server" />
<br />
<asp:Label ID="MessageThree" runat="server" />
</form>
</body>
</html>
SelectedItem.Value和SelectedValue
功能差不多,还是有区别的,如果没有一个List Item被选中,那么SelectedItem.Value将会报错,SelectedValue
的值为空字符串。
貌似是JS取的?
Text 列表中显示的文本。
Value 与某个项关联的值。设置此属性可使您将该值与特定的项关联而不显示该值。
Selected 布尔值,指示该项是否被选定。 DropDownList 控件的 Items 是一个标准集合,您可以向它添加项对象。selecteditem就是指你选定的项。
selecteditem.text 就是选定项的文本。
selecteditem.value 就是选定项的关联值。
例如我们可以用text 显示人名,而value值绑定人员的id。selectedvaule就是直接指你选定的关联值。(vs2005中才有,vs2003中没有)