如何使DropdownList 默认选中为从数据库中查询的字段
这里有两种方式
第一种:利用text方法
ListItem item=DropDownlist.Items.FindByText("数据库中的查询的字段");
if(item != null)
{
item.Selected = true;
}
第二种:利用value
<asp:DropDownList ID="ddl_Answer" runat="server" AutoPostBack="true" Font-Size="9pt" Width="43px">
<asp:ListItem Value="A">A</asp:ListItem>
<asp:ListItem Value="B">B</asp:ListItem>
<asp:ListItem Value="C">C</asp:ListItem>
<asp:ListItem Value="D">D</asp:ListItem>
</asp:DropDownList>
ListItem item=DropDownlist.Items.FindByValue("C");
if(item != null)
{
item.Selected = true;
}
本文介绍了两种方法使ASP.NET DropdownList控件默认选中从数据库查询到的字段值。一种方法是通过使用text方法,另一种是利用value属性来设置默认选中项。
3861

被折叠的 条评论
为什么被折叠?



