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

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.

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)

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

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.