Join the Stack Overflow Community
Stack Overflow is a community of 6.7 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am binding a gridview using SqlDataSource and I am assigning the SQL select command from code behind to SqlDataSource . I have also enabled pagination in my GridView with page size 25.

Now what I want to know is if I am assigning query from code behind then does SqlDataSource takes care of pagination. I mean it should fetch 25 records at a time based on the selected page number.

I am concerned because my GridViewis showing data too slow and I feel that SqlDataSource is fetching all 9174 records (result set of my query) and displaying first 25 of them in first page. When I switch to second page it looks like it is fetching all 9174 records again and showing next 25 records.

Can anyone help me to understand if what I am assuming is correct or the flow in my case is different.

share|improve this question

yes you are correct. It gets all the records and then get 25 records for specified page index. If you feel it is inefficient, then you have to manually do that. First get count of records(In your case 9174) then 9174/25 is the number of pages. when loading grid get only first 25 record and display it in grid. Also manually add next and previous buttons to navigate. According to current page(lets say 6) if next page clicked(want to get the 7 page data 151 record to 175 record) then get that 25 records and bind it in next button click. Like this you should have to manually do that by maintaining the current page number.

share|improve this answer

If you are doing it be setting datasource in the Selecting event:

protected void MyDataSourceSelecting(object sender, LinqDataSourceSelectEventArgs e)
{
    e.Result = SomeIqueryableValue;
}

Then the grid will handle paging automatically using the IQueryable deferred execution.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.