473,382 Members | 1,622 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

DataGrid.DataBind() and SortCommand

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
1 2035
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: xrow | last post by:
Hello I have a simple webservice / c# application that receives data from server and prints the data in the asp:datagrid control I have problem when sorting data in datagrid I have created...
2
by: Ken Tucker | last post by:
I've read about this issue in many articles across the net... But haven't found a solution. I see all kinds of custom code to perform sorting with datagrids, but my example is so simple, I must...
2
by: enak | last post by:
I can not get my datagrid to page. I have a datagrid that I can sort 2 of the columns. This works great. I added paging and when I display the dg it shows 5 pages. (I am showing page numbers at...
7
by: DC Gringo | last post by:
I have a datagrid that won't sort. The event handler is firing and return label text, just not the sort. Here's my Sub Page_Load and Sub DataGrid1_SortCommand: -------------------- Private...
1
by: Sameeksha | last post by:
Hello, I've a datagrid whose AllowSorting property is set to True. The datagrid is bound to northwind table suppliers. I've handled the SortCommand event of the datagrid control. But somehow the...
6
by: Dee | last post by:
Hi The paging numbers of my DataGrid dont actually page. What can be the cause? Everyting else seems to work. Thanks Dee
5
by: tshad | last post by:
Is there a way to carry data that I have already read from the datagrid from page to page? I am looking at my Datagrid that I page through and when the user says get the next page, I have to go...
4
by: Joe | last post by:
Hello, I have a datagrid in an nested html table (one table inside of another table) and have set the allowsSorting property to true. I've created in the code-behind a method (Sub - I'm using...
0
by: rupalirane07 | last post by:
Both grids displays fine. But the problem is only parent datagrid sorting works fine but when i clik on child datagrid for sorting it gives me error: NullReferenceException error Any...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.