dropdownlist与gridview的关联

来源:互联网 发布:绝密淘宝小类目 编辑:程序博客网 时间:2024/06/05 21:02
 
设置一个按钮,在CLICK事件下分别获取DROPDOWNLIST的TEXT的值,再根据这3个值用SQL语句进行查询!代码如下protected void Button_Click(object sender, EventArgs e)             {                SqlConnection conn = new SqlConnection("Data Source=(local);Initial Catalog=你的数据库名;Integrated Security=True");                string str1 = this.DropDownList1.SelectedItem.Text;                string str2 = this.DropDownList2.SelectedItem.Text;string str3 = this.DropDownList3.SelectedItem.Text;                       DataSet ds = new DataSet();                       SqlDataAdapter da = new SqlDataAdapter("SELECT * FROM table WHERE Column1 like '%" + str1 + "%'and Column2 like '%" + str2 + "%' and Column3 like '%" + str3 + "%'", conn);                       da.Fill(ds, "你的表名");                       GridView1.DataSource = ds;                       GridView1.DataMember = "你的表名";                       GridView1.DataBind();                    }
原创粉丝点击