selectdvalue  selecteditem.value  selecteditem.text  好混淆,究竟是什么东西呢?

解决方案 »

  1.   

     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> 
      

  2.   


    SelectedItem.Value和SelectedValue
    功能差不多,还是有区别的,如果没有一个List Item被选中,那么SelectedItem.Value将会报错,SelectedValue
    的值为空字符串。
      

  3.   

    selectdvalue
    貌似是JS取的?
      

  4.   

    比如一个DropDownList 属性 说明 
    Text 列表中显示的文本。 
    Value 与某个项关联的值。设置此属性可使您将该值与特定的项关联而不显示该值。 
    Selected 布尔值,指示该项是否被选定。 DropDownList 控件的 Items 是一个标准集合,您可以向它添加项对象。selecteditem就是指你选定的项。
    selecteditem.text 就是选定项的文本。
    selecteditem.value 就是选定项的关联值。
    例如我们可以用text 显示人名,而value值绑定人员的id。selectedvaule就是直接指你选定的关联值。(vs2005中才有,vs2003中没有)