不知道大家有没有遇到过这样的。<asp:ListItem Value="8">XXX</asp:ListItem>
<asp:ListItem Value="5">xxx</asp:ListItem>
 <asp:ListItem Value="3">xxx</asp:ListItem>
<asp:ListItem Value="4">xxx</asp:ListItem>
 <asp:ListItem Value="5">xxx</asp:ListItem>
 <asp:ListItem Value="7">xxxx</asp:ListItem>上面同LIst里面的Item可是后台取值的时候Me.ddlPZ.SelectedItem.Text和Request.Form(Me.ddlPZ.UniqueID)这两种方法都无法取到正确的值,如果把上面Value属性去掉就可以正常取值了,或者Value的值也按序号排也可以正常。是什么原因啊。好像以前没有这样的事。  

解决方案 »

  1.   

    if(!IsPostBack)
    ddlPZ.SelectedValue
      

  2.   


    Value里的值是Javascript里取出来有用的。Value不能有相同的吗?Value是String类型啊。
      

  3.   


    页面是用JS取Value的值,后台取的是Text的值的
      

  4.   


    ddlPZ.SelectedItem.Text  //取文本
    ddlPZ.SelectedValue      //取值
      

  5.   

    看一下浏览器端的HTML源代码,就一目了然了。注意:Request.Form是按照name属性取的。
      

  6.   

    <%@ Page Language="C#" AutoEventWireup="true" %><!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)
      {
        Response.Write("你选择了:" + A.SelectedValue + " - " + A.SelectedItem.Text + " - " + A.SelectedItem.Value + "-" + A.Text);
      }
    </script>
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head id="Head1" runat="server">
      <title></title>
    </head>
    <body>
      <form id="form1" runat="server">
      <asp:DropDownList ID="A" runat="server">
        <asp:ListItem Value="8">XXX</asp:ListItem>
        <asp:ListItem Value="5">xxx</asp:ListItem>
        <asp:ListItem Value="3">xxx</asp:ListItem>
        <asp:ListItem Value="4">xxx</asp:ListItem>
        <asp:ListItem Value="5">xxx</asp:ListItem>
        <asp:ListItem Value="7">xxxx</asp:ListItem>
      </asp:DropDownList>
      <asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Button" />
      </form>
    </body>
    </html>
      

  7.   

    dropdownlist  重复项
    删除重复记录
      

  8.   

      <asp:ListItem Value="5">xxx</asp:ListItem>  有两个一样的,重复了
      

  9.   

    重复也可以取到的值
    <%@ Page Language="VB" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><script runat="server">  Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
         Response.Write("你选择了:" + A.SelectedValue + " - " + A.SelectedItem.Text + " - " + A.SelectedItem.Value + "-" + A.Text)
      End Sub
    </script><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
     <asp:DropDownList ID="A" runat="server">
        <asp:ListItem Value="8">XXX</asp:ListItem>
        <asp:ListItem Value="5">xxx</asp:ListItem>
        <asp:ListItem Value="3">xxx</asp:ListItem>
        <asp:ListItem Value="4">xxx</asp:ListItem>
        <asp:ListItem Value="5">xxx</asp:ListItem>
        <asp:ListItem Value="7">xxxx</asp:ListItem>
      </asp:DropDownList>
        <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Button" />
        </form>
    </body>
    </html>
      

  10.   


    Text没有重复,重复的是Value,Value不是String类型的吗,Value重复也会出问题吗?以前没有注意过。今天调试的时候才看到。
      

  11.   


    重复后我在后台取值的时候有时候会乱,比如页面上选中的是第二个Item,获取的时候却获取到第4个Item的Text如果不设Value或者Value按顺序排列就不会出现这种情况。
      

  12.   

    还有一个情况,DropdownList是服务器控件,我在页面上放一个服务器Button,不做任何操作,当我点击Button时,DroPDownList里的SelectedIndex有些有会改变,有些不会(当前是第三个Item,点了Button后会跳到另一个Item了,有些就不会。同样是Value的原因)。
      

  13.   

    页面的<asp:DropDownList ID="DropDownList1" runat="server" onchange="GetAddress()">
                        <asp:ListItem Value="3">摆脱单身牌阵</asp:ListItem>
                        <asp:ListItem Value="6">突破暧昧牌阵</asp:ListItem>
                        <asp:ListItem Value="7">亲密关系牌阵</asp:ListItem>
                        <asp:ListItem Value="5">缘分检测牌阵</asp:ListItem>
                        <asp:ListItem Value="4">危机救援牌阵</asp:ListItem>
                        <asp:ListItem Value="6">三角关系牌阵</asp:ListItem>
                        <asp:ListItem Value="5">解脱之道牌阵</asp:ListItem>
                        <asp:ListItem Value="3">余情未了牌阵</asp:ListItem>
                        <asp:ListItem Value="6">二择一牌阵</asp:ListItem>
                        <asp:ListItem Value="4">恋爱运势牌阵</asp:ListItem>
                    </asp:DropDownList>
    后台的'obj.QA = Request.Form(Me.ddlPZ.UniqueID)
            obj.QA = Me.ddlPZ.SelectedItem.Text
    上面是我的代码,取Text会乱,有时取不到当前的值页面回传后SelectedIndex也会改变。
      

  14.   


    是回传后下拉框的值也会改变。也是出现在取Value值出问题的选项。
      

  15.   


    <%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="Set_Default" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <asp:DropDownList ID="DropDownList1" runat="server">
                        <asp:ListItem Value="3">摆脱单身牌阵</asp:ListItem>
                        <asp:ListItem Value="6">突破暧昧牌阵</asp:ListItem>
                        <asp:ListItem Value="7">亲密关系牌阵</asp:ListItem>
                        <asp:ListItem Value="5">缘分检测牌阵</asp:ListItem>
                        <asp:ListItem Value="4">危机救援牌阵</asp:ListItem>
                        <asp:ListItem Value="6">三角关系牌阵</asp:ListItem>
                        <asp:ListItem Value="5">解脱之道牌阵</asp:ListItem>
                        <asp:ListItem Value="3">余情未了牌阵</asp:ListItem>
                        <asp:ListItem Value="6">二择一牌阵</asp:ListItem>
                        <asp:ListItem Value="4">恋爱运势牌阵</asp:ListItem>
                    </asp:DropDownList>
        </div>
        
        <asp:Button ID="Button1" runat="server" Text="Button" />
        </form>
    </body>
    </html>
    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
            Response.Write(Me.DropDownList1.SelectedItem.Text)
        End Sub
    大家可以试试看。
      

  16.   

    你可以按照这样的格式处理
    <asp:ListItem Value="3|摆脱单身牌阵">摆脱单身牌阵</asp:ListItem>
    因为得到值是安装value来标识的
      

  17.   

    我现在不用Value了。在前台通过下拉框的Text来判断返回哪个值。我前台也只是想要得到数字类的Value而已,像级联那种效果。