I have gridview and its binded with datasource which is created in the code behind file. And I needed to enable sorting and paging in the easiest way so I wrote as following -
In button's click event
SqlDataSource dataSource = new SqlDataSource(ConfigurationManager.ConnectionStrings["connstr"].ConnectionString, searchQuery);
dataSource.SelectCommandType = SqlDataSourceCommandType.Text;
dataSource.SelectCommand = searchQuery;
if (txtSearchQuery.Text != "")
{
dataSource.SelectParameters.Add("searchQuery", txtSearchQuery.Text);
}
gridBookings.DataSourceID = dataSource.ID;
However, when the button was clicked, the gridview wasn't populated with data. Any ideas?