I have a GridView
bound to a SqlDataSource
with a default SelectCommand
defined as such:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" DataSourceMode="DataSet"
ConnectionString="<%$ ConnectionStrings:MyConn %>"
ProviderName="MySql.Data.MySqlClient"
SelectCommand="select * from blah blah" />
There are cases where I have to change this query dynamically at runtime, so I do the following:
SqlDataSource1.SelectCommand = sql; // 'sql' is the new query
GridView1.PageIndex = 0;
GridView1.EditIndex = -1;
GridView1.SelectedIndex = -1;
GridView1.DataBind();
updatePanel.Update();
This works just fine actually, but when I click the pagination controls, the result set defaults back to the SelectCommand
defined in the SqlDataSource1
.
Any way around this?
Thanks, Mark
See Question&Answers more detail:os