Paging in a grid view troubles
-
I am currently having a few problems with a grid view I am working with. The gridview is set up to display a list of calls that have been received. This is populated via a view on the sql server database. I have a number of options on the page that I can filter the gridview on. The ides is that the user can click on a dropdown list and select some options and then click a button ‘apply’ which then composes a new query I then set this string (msg) to be the select command of the gridview using…
sqlGridView.SelectCommand = "SELECT * FROM [uvw_supportcalllist] " & msg GridView1.DataBind()
This applys the filter brilliantly…all is well and good so far. However I have set the paging attributes to true and set the pages length thing to be 20 now if I apply my filter like above and then go to the next page I lose my applied filter. I realise I am missing something somewhere, I have attempted to call databind again in the paging event of the page but that doesn’t work. Can someone help me out? Am I applying my filter wrongly? Or is there a better of paging the gridview? Any help would be most appreciated. Cheers Ian Caddick -
I am currently having a few problems with a grid view I am working with. The gridview is set up to display a list of calls that have been received. This is populated via a view on the sql server database. I have a number of options on the page that I can filter the gridview on. The ides is that the user can click on a dropdown list and select some options and then click a button ‘apply’ which then composes a new query I then set this string (msg) to be the select command of the gridview using…
sqlGridView.SelectCommand = "SELECT * FROM [uvw_supportcalllist] " & msg GridView1.DataBind()
This applys the filter brilliantly…all is well and good so far. However I have set the paging attributes to true and set the pages length thing to be 20 now if I apply my filter like above and then go to the next page I lose my applied filter. I realise I am missing something somewhere, I have attempted to call databind again in the paging event of the page but that doesn’t work. Can someone help me out? Am I applying my filter wrongly? Or is there a better of paging the gridview? Any help would be most appreciated. Cheers Ian CaddickI am guessing there is a pretty good chance that you are doing an initial load in the page load event? If you have code like that you need to check to see if the page load is a postback or not. You would only want to call that code on the first page load, not on a post back which is what happens when you page. So check the IsPostback property of the page. You code would be something like: If (!IsPostBack) { //Initial bind code here } Hope that helps. Ben
-
I am guessing there is a pretty good chance that you are doing an initial load in the page load event? If you have code like that you need to check to see if the page load is a postback or not. You would only want to call that code on the first page load, not on a post back which is what happens when you page. So check the IsPostback property of the page. You code would be something like: If (!IsPostBack) { //Initial bind code here } Hope that helps. Ben
Thanks but no, I already do that I am in vb but its the same thing I do
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load If Not IsPostBack() Then Initialise() End If End Sub
Thanks for trying tho Cheers Cads