Asp.Net控件使用小记
1. DropDownList绑定方法
1)前台绑定
<asp:DropDownList ID="Type" runat="server" AutoPostBack="False" onselectedindexchanged="Type_SelectedIndexChanged" class="TableData"> <asp:ListItem Value="0">选择新闻类型</asp:ListItem> <asp:ListItem Value="1">日程公告</asp:ListItem> <asp:ListItem Value="2">工作公告</asp:ListItem> </asp:DropDownList>
2)后台不通过读数据库绑定
dropList1.Items.Add(new ListItem("发送人", "1")); dropList1.Items.Add(new ListItem("收信人", "2"));
3)后台通过数据库绑定
IList<SystemMessageTypeDto> list = service.GetMessageTypeAll(); dropList2.DataSource = list; dropList2.DataTextField = "TypeName"; dropList2.DataValueField = "ID"; dropList2.DataBind();
4)设置选定项
ListItem item = typeDropList.Items.FindByValue(hiddType.Value); item.Selected = true;