Hi everyone,
In my project, i am using a webgrid to do paging and sorting. I am doing both of these using Linq.skip().take()
With sorting, i use the Grid Sortcolumn event handler. With paging, i'm sending the page number via query string and the code behind will take the page number from the query string and skip records.
The problem i am facing now is on the initial load, the sortcolumn even handler will work every time i click on a column to be sorted, however, once i go to a new page (query string), whenever i try to click on a sorted column, the sort column event handler will not be called. I can see the page is getting postback, but still no sort column even handler.
Any ideas?
I fixed my problem, however, i changed the way i did paging. Before, i paging using links and sending the page number to a query string. Now, i am using the custom paging function on the grid. I'm still using Linq so not all the data is loaded to the grid. In order to do this, i had to use an array that would store the page numbers and then load it into the grid on InitializeLayout event. So far this is working for me.
It really depends on your setup. Here is what I am trying (against Linq To Sql for NorthWind) and it is working perfectly - I guess if you pass the correct page via GET parameter in the query string, it can be used in the InitializeDataSource event of the grid and you can proceed with binding against your Linq datasource
public partial class _Default : System.Web.UI.Page { protected override void OnInit(EventArgs e) { base.OnInit(e); UltraWebGrid1.InitializeDataSource += new Infragistics.WebUI.UltraWebGrid.InitializeDataSourceEventHandler(UltraWebGrid1_InitializeDataSource); } void UltraWebGrid1_InitializeDataSource(object sender, Infragistics.WebUI.UltraWebGrid.UltraGridEventArgs e) { DataClassesDataContext dataContext = new DataClassesDataContext(); UltraWebGrid1.DataSource = dataContext.Categories.Skip(3).Take(3).ToList(); UltraWebGrid1.DataBind(); } protected void Page_Load(object sender, EventArgs e) { }}
Wanted to find out whether you found a resolution to your problem. I am having the same challenge. Not certain it is master page related, but it is the only difference as the same ascx works fine when loaded up in a normal page.
Thanks
Tony,
This is an example of how i used linq and databinding.
var query = from p in db.example select p;
ExampleGrid.Clear();
ExampleGrid.DataSource = query.Skip((PageNumber - 1) * NumberOfRowsToDisplay).Take(NumberOfRowsToDisplay).ToList();
ExampleGrid.DataBind();
I databind to the grid almost all over the place such as when i'm sorting or paging. I will try to bind the data in the initalizedatasource event and see if that will work.
Thanks!
A couple of important questions - what is your datasource, and how are you binding? Are you using the LinqDataSource, or are you binding to a IQueryable collection? When do you assign data to the grid control? The recommended databinding stragety for the WebGrid is to assign a datasource in the grid's InitializeDataSource event. If you're not connecting your data there, you may want to try and see if that fixes the problem.
Hope this helps,
-Tony