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的选中项  从数据库获取数据 这时候就看着上班代码 就可以更新了

 

你可能感兴趣的:(asp.net利用listbox查看内部列)