By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,725 Members | 1,040 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,725 IT Pros & Developers. It's quick & easy.

DataGrid.DataBind() and SortCommand

P: n/a
I have a DataGrid on my ASPX and I'm confused about the interaction with the
page based on whether the page is just loading or is being reloaded with a
call to the SortCommand of the DataGrid:

If I do the SQL query and the DataGrid.DataBind() in the Page_Load(), and
then I do it AGAIN inside the SortCommand function I set up, everyhting works
fine. But that seems inefficient because it means that the
DataGrid.DataBind() gets called twice: once on Page_Load, and then again with
the new sort criteria in the SortCommand function.

But what's weird is that if I take the DataGrid.DataBind() OUT of the
Page_Load, then the SortCommand function never even gets called and I can't
understand why that would be.
May 21 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Actually you need to bind data to the datagrid after the sort command or
after the page change or in such operations on that data grid. Alex there is
problem with your approach actually. Calling DataBind for DataGrid is not
expensive operation but calling sql query is expensive. What i infer from
your code that you are querying at the page load then binding , similarly you
are agian query on sort and bindng. you can query in pageload and store class
dataset variable and use it whenever you wnat to bind grid.

"Alex Maghen" wrote:
I have a DataGrid on my ASPX and I'm confused about the interaction with the
page based on whether the page is just loading or is being reloaded with a
call to the SortCommand of the DataGrid:

If I do the SQL query and the DataGrid.DataBind() in the Page_Load(), and
then I do it AGAIN inside the SortCommand function I set up, everyhting works
fine. But that seems inefficient because it means that the
DataGrid.DataBind() gets called twice: once on Page_Load, and then again with
the new sort criteria in the SortCommand function.

But what's weird is that if I take the DataGrid.DataBind() OUT of the
Page_Load, then the SortCommand function never even gets called and I can't
understand why that would be.

May 21 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.