首页上一页 1 下一页尾页 1 条记录 1/1页
在下拉列表里选择后在listbox中显示
发表在C#图书答疑
2011-03-16
是否精华
是
否
版块置顶:
是
否
大家好,我买了C#程序开发范例宝典,有个例子自己照编了一下,但没能调通,就是如何在下拉列表中选中班级,在listbox中显示出该班级所有学生的姓名。有高手能点拨我一下么?
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server=xx;Initial Catalog=xy;Persist Security Info=True;uid=sa;pwd=;");
conn.Open();
SqlCommand com = new SqlCommand("select 姓名 from xinxi where 班级=DropDownList1.Text", conn);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
this.ListBox1.Items.Add(dr[1].ToString());
}
conn.Close();
}
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server=xx;Initial Catalog=xy;Persist Security Info=True;uid=sa;pwd=;");
conn.Open();
SqlCommand com = new SqlCommand("select 姓名 from xinxi where 班级=DropDownList1.Text", conn);
SqlDataReader dr = com.ExecuteReader();
while (dr.Read())
{
this.ListBox1.Items.Add(dr[1].ToString());
}
conn.Close();
}