当前位置:编程学习 > asp >>

asp.net利用listbox查看内部列

 protected void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
    {
 this.ListBox2.Items.Clear();
        string s = "select * from class where sid='" + this.ListBox1.SelectedValue + "'";
        SqlConnection ccc = new SqlConnection();
        ccc.ConnectionString = ConfigurationManager.ConnectionStrings["strcnn"].ConnectionString;
        SqlCommand cmm = new SqlCommand(s, ccc);
        ccc.Open();//调用数据库
        SqlDataReader myr;
        myr = cmm.ExecuteReader();
        while (myr.Read())
        {
            this.ListBox2.Items.Add(new ListItem(myr["classname"].ToString(), myr["id"].ToString()));
        }

}代码写在listbox1的SelectedIndexChanged属性里面

然后autopostback为ture就可以上传到服务器 

然后在里面写代码    获取listbox1的选中项  从数据库获取数据 这时候就看着上班代码 就可以更新了

 

摘自 liuningshiwoa的专栏
补充:Web开发 , ASP.Net ,
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,