DataGrid.DataBind() and SortCommand

G

Guest

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.
 
G

Guest

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,828
Latest member
LauraCastr

Latest Threads

Top