0

Hi
I need to know how to keep data in a gridview after postback. I am using sqlDataAdapter with DataSet to fill the gridview. But if you want to go to the second page of the gridview list it loses the data. Would it be best to create a Session and then a list and then set the session equals to the list?

Regards
Weppies

3
Contributors
4
Replies
5
Views
7 Years
Discussion Span
Last Post by Weppies
0

My suggestion, enclose the process that you're using to populate the gridview in the following construct:

if (!Page.IsPostBack)
{
    GridViewPopulation();
}

Replace "GridViewPopulation()" with a procedure for populating your GridView control and it should only load on the initial page load and not on a postback event, hopefully preserving your GridView content.

Hope this helps :) Mark as solved if it resolves your issue.

1

Attaching a dataset within session and binding data from session while paging records seems very easy but I belive it create worst scenerio for resouces especially when your datatable is huge.
I recommend passing your pageNumber and PageSize parameter to your stored procedure and evaluate the paging in following way.

WITH tmp AS 
	(
	SELECT 
		ROW_NUMBER() OVER (firstColumn) AS column1,
		2ndColumn AS column2,
		3rdColumn AS column3,
	FROM [yourTable] WITH (NOLOCK) 
	WHERE
		firstColumn = @myCondition
	)
	SELECT
		*
	FROM
		tmp
	WHERE
		SN >((@PageNumber - 1) * @PageSize)
		AND SN <= (@PageNumber * @PageSize)
0

Are you refering to the gridview's PageIndex and PageCount?

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.