1.DropDownList
前端代码aspx:
<asp:DropDownList ID="ddl_meetingroom" runat="server"></asp:DropDownList>
后台代码aspx.cs:
sql = "select id,name from OA_Meeting_Room";
DataTable dt = SqlHelper.ExecuteDataset(SqlHelper.connectionString, CommandType.Text, sql).Tables[0];
ddl_meetingroom.DataSource = dt;
ddl_meetingroom.DataTextField = "name"; //控件显示的字段
ddl_meetingroom.DataValueField = "id"; //控件绑定值
ddl_meetingroom.DataBind();
//显示“请选择”
ListItem lt = new ListItem();
lt.Text = "--请选择--";
lt.Value = "0";
lt.Selected = true;
DropDownList1.Items.Add(lt);