Have you tried using the GridView.FilterExpression propety rather than
changing the SelectCommand, this will do what you want, it uses the syntax
GridView.FilterExpression = "FieldName = Value";
You can also add parameters by using the GridView.FilterParameters collection.
Below is some code from a page that i have written that updates the
datasource of a GridView based on which option is selected in a DropDownList
control.
ControlParameter cprViewState = new ControlParameter();
cprViewState.ControlID = ddlSelectView.ID.ToString();
cprViewState.PropertyName = "SelectedValue";
cprViewState.Name = "ViewState";
cprViewState.Type = TypeCode.Int32;
SqlDataSource1.FilterExpression = "Status = {0}";
SqlDataSource1.FilterParameters.Add(cprViewState);
the {0} in the filter expression represents the first item in the
FilterParameters collection. {1}, {2} etc would work for the second and
third items etc.
"Bishop" wrote:
I have a number of simple select queries that a user needs to be able to
execute and display the data on the screen in a gridview. My thought was
that I could use a Gridview set to dymanically generate columns and bound to
a SQLDataSource. Then the user can click buttons (or whatever) and it
changes the SelectCommand property of the SQLDataSource and re-binds the
GridView.
That worked great until I enabled paging. When paging is clicked, it always
reverts back to the default SelectCommand that's embeded with the control.
Any thoughts on what I can do to make this work?