当前位置: 代码迷 >> ASP.NET >> 怎么读出DropDownList已经邦定的值
  详细解决方案

怎么读出DropDownList已经邦定的值

热度:5414   发布时间:2013-02-25 00:00:00.0
如何读出DropDownList已经邦定的值?
已经邦定,邦定的表里有2列值,如何在DropDownList读出?我这里写的不对吧?谁能给我个   我查了半天了。。。用不用循环?   谢谢大家乐
      <asp:templatecolumn   >
<edititemtemplate>
<asp:dropdownlist   id   =   "txtsort "   selectedindex= ' <%#container.dataitem( "data_sort ")-1%> '   runat   =   "server ">
<asp:listitem> 1 </asp:listitem>
<asp:listitem> 2 </asp:listitem>
<asp:listitem> 3 </asp:listitem>
<asp:listitem> 4 </asp:listitem>
<asp:listitem> 5 </asp:listitem>
<asp:listitem> 6 </asp:listitem>
<asp:listitem> 7 </asp:listitem>
</asp:dropdownlist>
</edititemtemplate>
</asp:templatecolumn>


------解决方案--------------------------------------------------------
晕,原来你不知道怎么绑定,一个例子

SqlConnection cnn = new SqlConnection( "server=CNN;database=foodshop;uid=sa;password= ");
SqlDataAdapter da = new SqlDataAdapter();
da.SelectCommand = new SqlCommand( "select id, food_id, food_name from food ", cnn);
DataSet ds = new DataSet();
da.Fill(ds, "myFood ");
DataTable dt = ds.Tables[ "myFood "];

//绑定数据
ddl.DataSource = dt;
ddl.DataValueField = "food_id ";
ddl.DataTextField = "food_name ";
ddl.DataBind();
------解决方案--------------------------------------------------------
看amandag(高歌)给的代码,已经很全面了
  相关解决方案