开发者

DataGridView allow paging , why it get all data?

hi i have simple gridView wi开发者_如何学Cth AllowPaging set to true, i bind data to it as follow:

            RulesGridView.DataSource = GetData();
            RulesGridView.DataBind();

where

 public static IEnumerable GetData()
    {
        return from gc in context.Current.SampleTable
               where gc.SameField == sameValue
               select new
                          {
                              example = SampleData
                          };
    }

In sql SampleTable i have 4000 rows, my question is , why gridView is taking all data from this table, instead of only first page of gridview? i checked with sql profiler , and that is really true, displaying just first page on gridview couse downloading all gridview pages. Can i change it to take from sql only so many what is enough to display data on first page of DataGrid, and then if user click second page , gridview will ask for another data?


Because you are binding method which simple returns all records.

Possible solution: You have to modify your GetData method to accept parameter which will mark pagination and apply it in inner query. Then at each "pageNext/Prev" event, you just modify that parameter to new value.

Edit:

Codeproject custom paging for gridView
Aspsnippets about pagination


I like this discussion http://www.west-wind.com/weblog/posts/211.aspx; it may give you additional insight or decide that it is time to pull every hair from Gates.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜