Dear all,
I am trying to filter my gridview using both text.box and DDL. I would like to be able to filter my search as following, if search for textbox1.name = corn and ddl.priceType = talk, the girdview should display results of corn with price_type = talk.
I am using the following code and I cannot get the above logic to work:
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text != "")
{
String constr = ConfigurationManager.ConnectionStrings["###"].ConnectionString;
SqlConnection con = new SqlConnection(constr);
con.Open();
SqlCommand cmd = new SqlCommand("select [Name], CUSIP, ISINs, [Size (m)],[Current size],priceTalk, [Decimal price], Cover, Type, UploadDate from [dbo].[database_BWICs] where Name like '%" + TextBox1.Text + "%'");
cmd.Connection = con;
cmd.Parameters.Add("@Name", SqlDbType.NVarChar).Value = TextBox1.Text;
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();
Label1.Text = "Found " + Convert.ToString(GridView1.Rows.Count) + " records with the keyword(s): ";
}
else if (DropDownList1.SelectedValue != "" && TextBox1.Text != "")
{
string query = string.Format("select [Name], CUSIP, ISINs, [Size (m)],[Current size],priceTalk, [Decimal price], Cover, Type, UploadDate from [dbo].[database_BWICs] where Cover = '{0}' and Name like '%" + TextBox1.Text + "%'", DropDownList1.SelectedValue);
DataSet dt = GetData(query);
GridView1.DataSource = dt;
GridView1.DataBind();
}
else
{
BindDate(TextDateFrom.Text, TextDateTo.Text);
Label1.Text = "Found " + Convert.ToString(GridView1.Rows.Count) + " records with the keyword(s): ";
}
}
Many thanks