Groups | Blog | Home
all groups > asp.net datagrid control > october 2005 >

asp.net datagrid control : Optimizing binding


Tumurbaatar S.
10/21/2005 12:00:00 AM
All my datagrids need editing, deleting, sorting and paging. Datagrid's view
state is enabled,
but it is disabled it for each DataGridItem after binding. Also, I use
DataAdapter instead of
DataReader because the last one does not work with paging and sorting.
My typical data binding code looks like this:

string sql = "SELECT .... FROM tbl"; // a query does not contain ORDER BY
clause
SqlDataAdapter cmd = new SqlDataAdapter(sql, conn);
DataSet ds = new DataSet();
cmd.Fill(ds);
DataView dv = ds.Tables[0].DefaultView;
dv.Sort = sort; // a string like "some_fld DESC, another_fld ASC"
DataGrid.DataKeyField = "key_fld"; // specify a key field for update/delete
events
DataGrid.DataSource = dv;
DataGrid.DataBind();

And I thought, may be, using a sorting order directly in a SELECT statement
can improve a performance? I.e.:

string sql = "SELECT .... FROM tbl ORDER BY " + sort;

and removing following line:

dv.Sort = sort;

Also, any other ideas to increase performance of data binding without adding
a much of code?

Elton Wang
10/21/2005 1:07:39 PM

If you compare Sorting in sql query and in dataview, the first one should
have better performance.

However when user clicks any column header in the datagrid, you need to
conduct sorting again. If you save the query result (dataview) in Session
when in the beginning, you can get the dataview from Session and sort it. It
apparently has better performance than re-query DB.


HTH


[quoted text, click to view]

AddThis Social Bookmark Button