这种下拉框效果是如何实现的? ---主分类1--- 子分类1 子分类2---主分类2--- 子分类1 子分类2数据是如何绑定到dropdownlist的,还有主分类只能看不能选 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 绑定前重新组织数据源,不能选 好象不太可能,除非你不要用dropdownlist,自己写一个存来展示 除了动态绑定数据或是整理数据源,还有个方法可以实现选项只能看不能选。<select><option>新闻</option><optgroup label='娱乐'></OPTGROUP><option>体育</option></select> 还是不明白,怎么组织,---主分类1--- 子分类1 子分类2 这样一堆做一项?那value和fieldtext怎么设定 想了半天,终于写到了public partial class _Default : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { DataTable dt=SelectClass(); for (int i = 0; i<dt.Rows.Count; i++) { DataTable dt2 = new DataTable(); string text="----"+dt.Rows[i]["name"].ToString()+"----"; string id=dt.Rows[i]["id"].ToString(); int id2= Convert.ToInt32(dt.Rows[i]["id"]); dt2 = SelectSubClass(id2); this.DropDownList1.Items.Add(new ListItem(text, id)); if (dt2.Rows.Count>0) { for(int j=0;j<dt2.Rows.Count;j++) { string text2=" --"+dt2.Rows[i]["name"]; string id3=dt.Rows[i]["id"].ToString(); this.DropDownList1.Items.Add(new ListItem(text2, id3)); } } } } private DataTable SelectClass() { SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connstr"]); DataTable dt = new DataTable(); SqlCommand cmd = new SqlCommand("select * from class where pid=0", SqlOpen(conn)); using (SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { dt.Load(sdr); sdr.Close(); } return dt; } private DataTable SelectSubClass(int id) { SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connstr"]); DataTable dt = new DataTable(); string sql = "select * from class where pid=" + id; SqlCommand cmd = new SqlCommand(sql, SqlOpen(conn)); using (SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection)) { dt.Load(sdr); sdr.Close(); } return dt; } private SqlConnection SqlOpen(SqlConnection conn) { if (conn.State==ConnectionState.Closed) { conn.Open(); } return conn; } private SqlConnection SqlClose(SqlConnection conn) { if (conn.State==ConnectionState.Open) { conn.Close(); } return conn; }} 用 treeview 可以做到的,先绑定 读取数据库中数值个数不定的数据的方法 兄弟们,你们有没有遇到过这样的怪问题? 各位大侠,小弟刚刚学php~~~急急急 怎样用javascript实现拖动复制表格背景颜色?急啊!! 表中行列的动态添加 层被ActiveX 控件挡住了怎么办? 打开一个页面的同时,如何让令一个页面在20妙后显示啊? 在线求助,修改字段名,急! 关于实体字段取舍的疑惑 treeview控件为什么是灰色的,我为什么不能用 <param name="movie" value="shop.swf?id=<%=id %>/> 哪位大侠使用过.net开发WAP网站啊?
<select>
<option>新闻</option>
<optgroup label='娱乐'></OPTGROUP>
<option>体育</option>
</select>
---主分类1---
子分类1
子分类2 这样一堆做一项?
那value和fieldtext怎么设定
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
DataTable dt=SelectClass(); for (int i = 0; i<dt.Rows.Count; i++)
{
DataTable dt2 = new DataTable();
string text="----"+dt.Rows[i]["name"].ToString()+"----";
string id=dt.Rows[i]["id"].ToString();
int id2= Convert.ToInt32(dt.Rows[i]["id"]);
dt2 = SelectSubClass(id2);
this.DropDownList1.Items.Add(new ListItem(text, id));
if (dt2.Rows.Count>0)
{
for(int j=0;j<dt2.Rows.Count;j++)
{
string text2=" --"+dt2.Rows[i]["name"];
string id3=dt.Rows[i]["id"].ToString();
this.DropDownList1.Items.Add(new ListItem(text2, id3));
}
} }
} private DataTable SelectClass()
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connstr"]);
DataTable dt = new DataTable();
SqlCommand cmd = new SqlCommand("select * from class where pid=0", SqlOpen(conn));
using (SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(sdr);
sdr.Close();
}
return dt;
} private DataTable SelectSubClass(int id)
{
SqlConnection conn = new SqlConnection(ConfigurationManager.AppSettings["connstr"]);
DataTable dt = new DataTable();
string sql = "select * from class where pid=" + id;
SqlCommand cmd = new SqlCommand(sql, SqlOpen(conn));
using (SqlDataReader sdr = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
dt.Load(sdr);
sdr.Close();
}
return dt;
} private SqlConnection SqlOpen(SqlConnection conn)
{
if (conn.State==ConnectionState.Closed)
{
conn.Open();
}
return conn;
} private SqlConnection SqlClose(SqlConnection conn)
{
if (conn.State==ConnectionState.Open)
{
conn.Close();
}
return conn;
}
}