I have the following two controls in my code
gridview (for data display) sqldatasource (source of my gridview)
I want to change the gridview, but when I change the sqlcommandstring in my sqldatasource, in new view of my datagrid table sorting doesn't fire for the first click. Please see below for sqlcommandstring change process.
protected void Page_Load(object sender, EventArgs e)
{
try
{
if (IsPostBack)
{ // Restore saved sqlcommand in page refresh, please see below
SqlDataSource1.SelectCommand = ViewState["MySQL"].ToString();
}
}
catch (Exception ex){}
}
protected void btn_SearchLibrary_Click(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT * FROM Books WHERE id=1 OR id=2";
ViewState["MySQL"] = "SELECT * FROM Books WHERE id=1 OR id=2";
//Saves sqlcommand in viewstate, to restore it in page refresh.
}