<EditItemTemplate>
<asp:DropDownList ID="ddl_BigCategory" runat="server" DataTextField="BigCategoryName_CH" DataValueField="BigCategoryID" DataSource="<%# BindBigCate() %>" AppendDataBoundItems="True" SelectedValue='<%# Bind("bid") %>'>
<asp:ListItem Value="-1">請選擇類別</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>aspx.cs
public SqlDataReader BindBigCate()
{
SqlDataReader dr = null;
try
{
dr = product.GetBigCategories();
}
catch(Exception ex)
{
WebHelper.AlertAndBack(ex.Message);
}
return dr;
}
<asp:DropDownList ID="ddl_BigCategory" runat="server" DataTextField="BigCategoryName_CH" DataValueField="BigCategoryID" DataSource="<%# BindBigCate() %>" AppendDataBoundItems="True" SelectedValue='<%# Bind("bid") %>'>
<asp:ListItem Value="-1">請選擇類別</asp:ListItem>
</asp:DropDownList>
</EditItemTemplate>aspx.cs
public SqlDataReader BindBigCate()
{
SqlDataReader dr = null;
try
{
dr = product.GetBigCategories();
}
catch(Exception ex)
{
WebHelper.AlertAndBack(ex.Message);
}
return dr;
}
解决方案 »
- treeview打开的图片加载无效.
- using Dundas.Charting.WebControl; 引用不到!
- 求一个网站投票系统
- 我用remoting试着编写一个聊天程序但是无法返回客户端发送的信息请问如何解决
- 求助啊
- ————关于前台显示后台变量或者函数返回值得请教,谢谢俄
- 关于b/s开发中的订单录入(200分求)
- 关于页面间特殊字符的传值的问题,希望大家帮帮我~~~
- 高难度问题!!!难道没有更好的办法了吗???(跨数据库(Oracle与SqlServer之间)操作的问题),敬请高手出马!
- 我们怎么对付客户无穷无尽的要求?
- 急。datagrid读不出来数据。
- 谁能告诉我这个问题怎么解决
如DB中 是aa,bb,cc
<asp:DropDownList ID="Drop1" runat="server" SelectedValue='<%# Bind("字段名称") %>'>
<asp:ListItem>aa</asp:ListItem>
<asp:ListItem>bb</asp:ListItem>
<asp:ListItem>cc</asp:ListItem>
</asp:DropDownList>
<asp:ListItem>aa</asp:ListItem>
<asp:ListItem>bb</asp:ListItem>
<asp:ListItem>cc</asp:ListItem>
</asp:DropDownList>
但多了个selected=true 就一直报错.谢谢
解决方法
设置DropDownList属性 AppendDataBoundItems="true"
然后添加一个固定的
<asp:ListItem Text="Null" Value=""></asp:ListItem>