asp.net如何通过选择dropdownlist的选项给一个GridView,绑定同一个sql数据库连接下的不同的表?(C#)
也尝试自己搞一搞,不过编译通不过啊。测试如果去掉switch...case语句,就绑定一个表就能通。sql_str="SELECT*FROMintbl423";然后Sql...
也尝试自己搞一搞,不过编译通不过啊。测试如果去掉switch ...case 语句,就绑定一个表就能通。sql_str="SELECT * FROM intbl423"; 然后SqlDataAdapter sqladp = new SqlDataAdapter(sql_str, cnn2);
急求高手指教!!! public partial class shizhi1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) DropDownList1.SelectedIndex = 2; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { switch (DropDownList1.SelectedValue) { case "423": Label1.Text = "表格intbl423"; Label2.Text ="423"; break; case "827": Label1.Text = "表格intbl827"; //UpdatePanel2中文本框label1对应的文本为 Label2.Text ="827"; break; case "934": Label1.Text = "表格intbl934"; Label2.Text = "934"; break; } } string sql_str; protected void Button1_Click(object sender, EventArgs e) { string chuan; chuan = Label2.Text.ToString(); if (true) { chuan = "827"; Response.Write("tongguole"); } SqlConnection cnn2 = new SqlConnection(); cnn2.ConnectionString = "Data Source=LBWin7\\SQLEXPRESS;Initial Catalog=intable1;Integrated Security=True;Pooling=False;"; cnn2.Open(); switch (chuan) { case "423": sql_str = "SECLECT * FROM intbl423"; break; case "827": sql_str = "SECLECT * FROM intbl827"; break; case "934": sql_str = "SECLECT * FROM intble934"; break; } SqlDataAdapter sqladp = new SqlDataAdapter(sql_str, cnn2); DataTable dt = new DataTable(); sqladp.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } 我这就是选择数据库连接sqlexpress.intable1.dbo下边不同的表,把表绑定到GridView控件。等着交,急求指正! 展开
急求高手指教!!! public partial class shizhi1 : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) DropDownList1.SelectedIndex = 2; } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { switch (DropDownList1.SelectedValue) { case "423": Label1.Text = "表格intbl423"; Label2.Text ="423"; break; case "827": Label1.Text = "表格intbl827"; //UpdatePanel2中文本框label1对应的文本为 Label2.Text ="827"; break; case "934": Label1.Text = "表格intbl934"; Label2.Text = "934"; break; } } string sql_str; protected void Button1_Click(object sender, EventArgs e) { string chuan; chuan = Label2.Text.ToString(); if (true) { chuan = "827"; Response.Write("tongguole"); } SqlConnection cnn2 = new SqlConnection(); cnn2.ConnectionString = "Data Source=LBWin7\\SQLEXPRESS;Initial Catalog=intable1;Integrated Security=True;Pooling=False;"; cnn2.Open(); switch (chuan) { case "423": sql_str = "SECLECT * FROM intbl423"; break; case "827": sql_str = "SECLECT * FROM intbl827"; break; case "934": sql_str = "SECLECT * FROM intble934"; break; } SqlDataAdapter sqladp = new SqlDataAdapter(sql_str, cnn2); DataTable dt = new DataTable(); sqladp.Fill(dt); GridView1.DataSource = dt; GridView1.DataBind(); } } 我这就是选择数据库连接sqlexpress.intable1.dbo下边不同的表,把表绑定到GridView控件。等着交,急求指正! 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询