绑定select标签
前端代码:
<select name="PositionId" id="PositionId" class="admin_index" runat="server">
<option value="0">==请选择==</option>
</select>
后台代码:
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getnamePost();
}
}
private void getnamePost()//岗位
{
//(int)CfgVoidInfo.IDInfo.GangWei 此处我写的是一个枚举(等于你想要赋值给ParentId的值)
bds = cfgBLL.GetList(" ParentId=" + (int)CfgVoidInfo.IDInfo.GangWei + " and State=1");
if (bds != null && bds.Tables.Count > 0)
{
foreach (DataRow dr in bds.Tables[0].Rows)
{
string strName = dr["Name"].ToString();
string value = dr["Id"].ToString();
ListItem list = new ListItem(strName, value);
PositionId.Items.Add(list);
}
}
PositionId.Value = Request.QueryString["PositionId"];
}