Click to See Complete Forum and Search --> : PostBack Issue with Filtered Gridview


Niyazi
09-12-2007, 04:19 PM
Hi Folks!

Assume that I have a GridView (gTest) and SQLDataSource (sTest) on the page.

The page shows the whole data from Table1 as default as in:

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

sTest.SelectCommand = "SELECT * FROM Table1"
gTest.DataSourceID = "sTest"

End Sub

If I put a filter button for the gridview that will filter the Table1 data depending on a date, the button event is:

Protected Sub bFilter_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles bFilter.Click

sTest.SelectCommand = "SELECT * FROM Table1 WHERE DateColumn = SomeNewDate"
gTest.DataSourceID = "sTest"

End Sub

After button is fired, gridview is showing up the filtered data.

BUT, when I want to sort the new filtered gridview it loading the old one (which was the default one) and sorting that former gridview.

How can I achieve to sort the filtered gridview?

Thanks,

- Niyazi

lmf232s
09-13-2007, 09:37 AM
Try this in your page_load sub. What this prevents is having the initial query run every time the page posts back. Even when you run the filtered query it still first runs that initial query in the page load. By adding the If statement its saying only run this code on page load and not on page postbacks.

See if this does not solve your problem.

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Not Page.IsPostBack Then
sTest.SelectCommand = "SELECT * FROM Table1"
gTest.DataSourceID = "sTest"
End If
End Sub

Niyazi
09-13-2007, 06:10 PM
Thanks Imf232s...