I have a gridView which initializes the page using the full contents of a table using source DataSourceID="SqlDataSource1"
testPage.aspx:
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$
ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT [Field1], [Field2], [Field3], [Field4] FROM [Analysis]
ORDER BY [Field1] DESC">
</asp:SqlDataSource>
(I've changed the real field names!).
This works fine and the gridView populates with the full table data. Based on another event I now want to change the SelectCommand to filter the table using the SQL WHERE clause. I've tried
testPage.aspx.cs:
protected void ctl04_ValueChanged(object sender, EventArgs e)
{
SqlDataSource1.SelectCommand = "SELECT [Field1], [Field2],
[Field3], [Field4] FROM [Analysis] WHERE [Field1] = 'items' ORDER BY
[Field1] DESC";
gridView1.DataBind();
}
The event fires and appears to run fine but gridView1 doesn't refresh/update and still contains the data for the full table.
Can anyone give some pointers how to get this working? Thanks
GridView.DataSource = null;before you reassign the select command. This should force theGridViewto rebind using the newSelectCommand. - Evan L