User1234927972 posted
Hi,
I currently have a database column bound to a drop down list, which I want to be used to filter what is displayed in the gridview below the drop down column.
I have tried assigning a query to a data adapter, that executes depending on what the selected index changed is.
Please find my C# code below for the Selected Index Changed. Apologies my SQL statement is so long, i needed lots of different columns from different tables in the gridview.
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=(local)\;Initial Catalog=SmallBatch;Integrated Security=True;");
SqlDataAdapter DataAdapter = new SqlDataAdapter(string.Format("SELECT Stock_Take.Username, Stock_Take.StockDate, Item.ItemDesc, Stock_Take_Item.BarQuantity, Stock_Take_Item.StorageQuantity, Stock_Take.StockTakeIDNew FROM Item INNER JOIN Stock_Take_Item ON Item.ItemID = Stock_Take_Item.ItemID INNER JOIN Stock_Take ON Stock_Take_Item.StockTakeIDNew = Stock_Take.StockTakeIDNew where Username = = '" & DropDownList1.SelectedValue & "'"), con);
DataTable table = new DataTable();
DataAdapter.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}
However i'm getting an error on Sql Adapter line 'Operator & cannot be applied to type 'string' and 'string'