C# 使用文本框和下拉菜单搜索数据,结果显示在gridview上

C# 使用文本框和下拉菜单搜索数据,结果显示在gridview上,c#,asp.net,gridview,C#,Asp.net,Gridview,请我想要一个场景,我将能够搜索数据使用文本框和下拉列表,结果显示在gridview上 </script> </script> //好的试试这个,在页面2.aspx页面加载事件 </script> string lastname = Request.QueryString["lastname"]; string location = Request.QueryString["location"]; string speciality = R

请我想要一个场景,我将能够搜索数据使用文本框和下拉列表,结果显示在gridview上

</script>  

</script>  

//好的

试试这个,在页面2.aspx
页面加载事件

</script>  
string lastname = Request.QueryString["lastname"];
string location = Request.QueryString["location"];
string speciality = Request.QueryString["speciality"];
SqlConnection cnn = new SqlConnection("Server=.;Database=db;Trusted_Connection=True;");
SqlDataAdapter adp = new SqlDataAdapter("select * from Table where lastname=@lname,location=@loc,speciality=@spec",cnn);
cnn.Open();
adp.SelectCommand.Parameters.AddWithValue("@lname", lastname);
adp.SelectCommand.Parameters.AddWithValue("@loc", location);
adp.SelectCommand.Parameters.AddWithValue("@spec", speciality);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();

希望有帮助,

试试这个,在page2.aspx
Page\u加载事件

</script>  
string lastname = Request.QueryString["lastname"];
string location = Request.QueryString["location"];
string speciality = Request.QueryString["speciality"];
SqlConnection cnn = new SqlConnection("Server=.;Database=db;Trusted_Connection=True;");
SqlDataAdapter adp = new SqlDataAdapter("select * from Table where lastname=@lname,location=@loc,speciality=@spec",cnn);
cnn.Open();
adp.SelectCommand.Parameters.AddWithValue("@lname", lastname);
adp.SelectCommand.Parameters.AddWithValue("@loc", location);
adp.SelectCommand.Parameters.AddWithValue("@spec", speciality);
DataTable dt = new DataTable();
adp.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();

希望有帮助,

从获取引用从获取引用不要使用
AddWithValue
。不要使用
AddWithValue
。和
</script>