I have a GridView
that already fetches some data from a SqlDataSource
.
The GridView
has sorting, paging, selection allowed.
Now when I'm clicking a button
, I'm creating a new DataSource
with a new Query, and I'm assigning the new DataSource
to this Grid, then I use .DataBind()
to update this grid, but after that, I cannot sort any column.
Dynamically Creating the new DataSource
SqlDataSource data = new SqlDataSource();
data.ConnectionString = SqlDataSource1.ConnectionString;
data.ProviderName = SqlDataSource1.ProviderName;
data.SelectCommand = "SELECT * FROM USERS";
GridView2.DataSourceID = "";
GridView2.DataSource = data;
GridView2.DataBind();
I tried to use the following:
GridView2.AllowSorting = true;
Still it didn't work, this is the error I get.
What am I missing here?