I have this list view that fetches data from local db, and there is a DropDownList to filter the items in asp:list view by their type. I did it with wizard.
After I bind them. it could only show items by filter. However, I could't show all items while I want both options.
So I decided to bind them myself in code behind, and I couldn't get any result here's my code in drop down list index changed event:
protected void BookListddl_SelectedIndexChanged(object sender, EventArgs e)
{
if (BookListddl.SelectedIndex == 0)
{
SqlDataSource dataSource = new SqlDataSource(ConfigurationManager.ConnectionStrings[0].ConnectionString
, "SELECT * FROM BookTbl");
dataSource.SelectCommandType = SqlDataSourceCommandType.Text;
dataSource.SelectCommand = "SELECT * FROM BookTbl";
dataSource.DataBind();
ListView1.DataSourceID = dataSource.ID;
ListView1.DataBind();
}
else
{
SqlDataSource dataSource = new SqlDataSource(ConfigurationManager.ConnectionStrings[0].ConnectionString
, "SELECT * FROM [BookTbl] WHERE [TypeId] = '" + BookListddl.SelectedValue + "'");
dataSource.SelectCommandType = SqlDataSourceCommandType.Text;
dataSource.SelectCommand = "SELECT * FROM [BookTbl] WHERE [TypeId] = '" + BookListddl.SelectedValue + "'";
dataSource.DataBind();
ListView1.DataSourceID = dataSource.ID;
ListView1.DataBind();
}
