asp.net 下拉列表无级数据绑定实现代码,需要的朋友可以参考下。
private void GetArticleCategory(string pid)
{
SqlConnection conn = new SqlConnection(“server=.;database=test;uid=sa;pwd=;”);
string sql = “select Articlesgroup_id,Groupname from Articlesgroup where Articlesgroup_parent_id=@pid order by Groupname”;
SqlCommand cmd = new SqlCommand(sql, conn);
SqlParameter Pid = new SqlParameter(“@pid”, SqlDbType.Int);
Pid.Value = pid;
cmd.Parameters.Add(Pid);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
while (sdr.Read())
{
this.Dro来源gaodai$ma#com搞$$代**码网pDownList1.Items.Add(new ListItem(toadd + ” ” + sdr[1].ToString(), sdr[0].ToString()));
toadd += “─┴”;
this.GetArticleCategory(sdr[0].ToString());
toadd = toadd.Substring(0, toadd.Length – 2);
}
sdr.Close();
conn.Close();
}
在Page_Load里调用
程序代码
{
this.keyword.Attributes.Add(“onfocus”,”if( this.value==’key key key’) {this.value=” };”);
if (!Page.IsPostBack)
{
this.GetArticleCategory(“0”);
}
this.DropDownList1.Items.Insert(0, new ListItem(“Search All”, “all”));
}
以上就是asp.net 下拉列表无级数据绑定实现代码的详细内容,更多请关注gaodaima搞代码网其它相关文章!