代码:var tds = $(elem).parent().parent().find("td"); //抓取GridView上的td
 $("#IDD").find("option:selected").text(tds.eq(0).html());控件:<asp:DropDownList ID="IDD" runat="server">
                        </asp:DropDownList>DropDownList下拉值为 ID NAME
                      1  AA
                      2  BB如果按第一句来写的话,就是给DropDownList加了一项,DropDownList选的值始终是1。
怎么写可以根据文本获取到ID??

解决方案 »

  1.   

    服务器控件  asp:dropdownlist  好像得设置个 属性 autocomplete   好像是这个  就是不让 提交form表单我感觉值 始终都是1     他是不是 每次都提交 form  然后   那个 dropdownlist 里面的值就 不可能变 
      

  2.   

    完全不知道你在说什么噢。。autopostback我又没用。
      

  3.   

    貌似想了下也可以用Ajax去处理返回所选文本的ID,谁能不用这方法帮忙解决下?谢谢!
      

  4.   

    function select(elem,text) {
                var count = $(elem).find("option").length;
                for (var i = 0; i < count; i++) {
                    if ($(elem).get(0).options[i].text == text) {
                        $(elem).get(0).options[i].selected = true;
                        break;
                    }
                } 
            }
      

  5.   

    DropDownList下拉值为 
    ID  NAME
      1 AA
      2 BB
    lz的意思是说从其他地方获取文本,然后在根据获取到的文本去获取DropDownList相应Name的ID值?
        <asp:DropDownList ID="DropDownList1" runat="server">
        <asp:ListItem Value="1">AA</asp:ListItem>
        <asp:ListItem Value="2">BB</asp:ListItem>
        </asp:DropDownList>
        <input id="Button1" type="button" value="button" />
        <script type="text/javascript">
            var txt = "BB";
            $("#Button1").click(function(){
                alert($("#DropDownList1 option[text='"+txt+"']").attr("Value"));
            })
        </script>