前台代码:
<label>选择类型</label>
<select class="form-control">
<%=list %>
</select>
后台代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Text;
namespace admin
{
public partial class news_Editor : System.Web.UI.Page
{
public StringBuilder list = new StringBuilder();
public string bId = "3";//大类ID
protected void Page_Load(object sender, EventArgs e)
{
//查询新闻类型
Date();
}
public void Date()
{
DataTable dt = sqlhelper.publicFun("select * from tb_sonType where type_Id=" + bId);
if (dt != null)
{
foreach (DataRow dr in dt.Rows)
{
list.Append(" <option value='" + dr["sonType_Id"] + "'>" + dr["sonType_Name"] + "</option>");
}
}
}
}
}
效果图: