select标签下拉框内容怎么从数据库中取出
1个回答
展开全部
在前台,
<select name="userId" id="userId">
<%=Getuser(Request["user"]) %>
</select>
在後台,
public string Getuser(object selected)
{
List<user> list = MyRegionManage.GetMyRegions();//
StringBuilder buffer = new StringBuilder(string.Format(Option, 0, "", "请选择"));
if (list != null)
{
foreach (user m in list)
{
string _checked = "";
if (selected != null && Convert.ToInt32(selected) == m.Id) _checked = "selected='selected'";
buffer.AppendFormat(Option, m.Id, _checked, m.Name);
}
}
return buffer.ToString();
}
<select name="userId" id="userId">
<%=Getuser(Request["user"]) %>
</select>
在後台,
public string Getuser(object selected)
{
List<user> list = MyRegionManage.GetMyRegions();//
StringBuilder buffer = new StringBuilder(string.Format(Option, 0, "", "请选择"));
if (list != null)
{
foreach (user m in list)
{
string _checked = "";
if (selected != null && Convert.ToInt32(selected) == m.Id) _checked = "selected='selected'";
buffer.AppendFormat(Option, m.Id, _checked, m.Name);
}
}
return buffer.ToString();
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询