SelectedIndex 取的是索引值还是取的是数据库里记录的value值呢?绑定不了数据库里的值。
<asp:TemplateColumn HeaderText="吨位">
<HeaderStyle Width="80px"></HeaderStyle>
<ItemTemplate>
<asp:DropDownList id="dy" runat="server" Width="60px"  SelectedIndex='<%#GetIndex(DataBinder.Eval(Container.DataItem,"vdy"))%> >
<asp:ListItem  Value="0">0</asp:ListItem>
<asp:ListItem Value="0.99">0.99</asp:ListItem>
<asp:ListItem Value="1">1</asp:ListItem>
<asp:ListItem Value="2">2</asp:ListItem>
<asp:ListItem Value="3">3</asp:ListItem>
<asp:ListItem Value="4">4</asp:ListItem>
<asp:ListItem Value="5">5</asp:ListItem>
<asp:ListItem Value="6">6</asp:ListItem>
<asp:ListItem Value="7">7</asp:ListItem>
<asp:ListItem Value="8">8</asp:ListItem>
<asp:ListItem Value="9">9</asp:ListItem>
</asp:DropDownList>
</ItemTemplate>
</asp:TemplateColumn>

解决方案 »

  1.   

    在绑定DropDownList的时候可以设置他的DataTextField和DataValueFiled
    DataTextField里面放的是显示的文本,DataValueFiled里面放的是标识他的值
    在选择后DropDownList.selectitem.value就是DataValueFiled里面的值
    DropDownList.selectitem.text就是DataTextField里面的值
      

  2.   

    DropDownList.SelectedIndex是选定item的索引
    不是值。
    要取值,用selectedvalue,要取选中item的文本,用.selectitem.text
      

  3.   

    SelectedIndex='<%#GetIndex(DataBinder.Eval(Container.DataItem,"vdy"))%>关键是这个我数据库里存放的是值。我应如何读取数据库中的值来选取下拉中对应的项目。
      

  4.   

    sql="SELECT CODE_VALUE,CODE_NAME FROM 吨位"
       .....
     这样绑定
      this.DropDownList1.DataSource = dr;//假设是datareader取的值
      this.DropDownList1.DataTextField = "CODE_VALUE";
      this.DropDownList1.DataValueField = "CODE_NAME";
      this.DropDownList1.DataBind();
       
      

  5.   

    我现在的意思是datagrid里的每一行的dropdownlist绑定数据库里对应的值