Optimizing binding

Discussion in 'ASP .Net Datagrid Control' started by Tumurbaatar S., Oct 21, 2005.

  1. 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?
     
    Tumurbaatar S., Oct 21, 2005
    #1
    1. Advertising

  2. Tumurbaatar S.

    Elton Wang Guest

    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


    "Tumurbaatar S." <> wrote in message
    news:%...
    > 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, Oct 21, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jordan
    Replies:
    2
    Views:
    2,572
    Jordan
    Feb 10, 2004
  2. Amit
    Replies:
    6
    Views:
    13,916
    Assimalyst
    Oct 24, 2006
  3. Replies:
    2
    Views:
    908
    Kevin Grover
    Oct 20, 2006
  4. JcFx
    Replies:
    0
    Views:
    317
  5. Vivek Nallur

    value binding and function binding

    Vivek Nallur, Sep 25, 2003, in forum: Ruby
    Replies:
    0
    Views:
    155
    Vivek Nallur
    Sep 25, 2003
Loading...

Share This Page