大哥们:
想把数据表中的字段 “学历”中的所有数据全部输出,有小学 中学 中专 大专 本科等,全部绑定在DropList中输出显示,相当于下拉框中显示的数据是从数据表中读出的,请问怎么做??以前只做rep 和datagird,请教给段能用的代码就行。急用的,谢谢!初学,请多多指导。
我做了一个,为什么在输出时,这样写就不行:
<asp:DropDownList id="FilmClass" runat="server"><asp:ListItem Value='<%# DataBinder.Eval(Container.DataItem,"FilmClass") %>'><%# DataBinder.Eval(Container.DataItem,"FilmClass") %></asp:ListItem>
</asp:DropDownList>
想把数据表中的字段 “学历”中的所有数据全部输出,有小学 中学 中专 大专 本科等,全部绑定在DropList中输出显示,相当于下拉框中显示的数据是从数据表中读出的,请问怎么做??以前只做rep 和datagird,请教给段能用的代码就行。急用的,谢谢!初学,请多多指导。
我做了一个,为什么在输出时,这样写就不行:
<asp:DropDownList id="FilmClass" runat="server"><asp:ListItem Value='<%# DataBinder.Eval(Container.DataItem,"FilmClass") %>'><%# DataBinder.Eval(Container.DataItem,"FilmClass") %></asp:ListItem>
</asp:DropDownList>
dataTextField 中写入相应的学历字段
然后绑定
DropDownList1.DataSource = ...
DropDownList1.DataTextField = "字段1";
DropDownList1.DataValueField = "字段2";
DropDownList1.DataBind();
DropDownList1.DataTextField = "值字段";
DropDownList1.DataValueField = "主键ID";
DropDownList1.DataBind();
<asp:ListItem Value='<%=value2%>
不能和datagrid一样绑定
方法
DropDownList1.DataSource = datatable1
DropDownList1.DataTextField = text;
DropDownList1.DataValueField = value;
DropDownList1.DataBind();
<asp:DropDownList id="FilmClass" runat="server">
的下面写什么,默认???
DropDownList1.DataSource = datatable1
DropDownList1.DataTextField = text;
DropDownList1.DataValueField = value;
DropDownList1.DataBind();
DropDownList1.DataTextField = text;
DropDownList1.DataValueField = value;
DropDownList1.DataBind();用后台绑定的