DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: Programatically building DataGrid columns with sorting.

  1. #1
    Todd Burvee Guest

    Programatically building DataGrid columns with sorting.


    I am trying to build a completely dynamic datagrid based on the XML returned
    from a servlet(essentially a webservice). The problem is that I need to
    programatically build the columns and the sortexpression for each column
    needs to be a different value than the display value. I can create the initial
    contents of the grid, but what I am experiencing is the SortCommand event
    doesn't fire if the autogeneratecolumns property of the datagrid is set to
    false. Does anyone know of a way to programatically build a datagrid that
    sorts? Thanks.



  2. #2
    Frank Oquendo Guest

    Re: Programatically building DataGrid columns with sorting.

    Todd Burvee wrote:
    > Does anyone know of a way to
    > programatically build a datagrid that sorts? Thanks.


    Can you show us the code you have so far?

    --
    There are 10 kinds of people. Those who understand binary and those who
    don't.

    http://code.acadx.com



  3. #3
    Ben Merrills Guest

    Re: Programatically building DataGrid columns with sorting.


    Not sure if this is what you want, but this is the code i use to generate
    a DataView for use with a DataGrid (including progmatic generation of Columns):

    DataTable dt = new DataTable();
    DataRow dr;

    dt.Columns.Add(new DataColumn("Account Type", typeof(string)));
    dt.Columns.Add(new DataColumn("Description", typeof(string)));
    dt.Columns.Add(new DataColumn("Next Charge Date", typeof(string)));
    dt.Columns.Add(new DataColumn("Options", typeof(string)));

    dr = dt.NewRow();
    dr[0] = accType.ToLower();
    dr[1] = data.GetString(4);
    dr[2] = (data.GetDateTime(3)).ToShortDateString().ToString();
    dr[3] = "[<a href='viewVisp.aspx?AccID=" + data.GetInt32(0).ToString() +
    "'>view</a>]";
    dt.Rows.Add(dr);
    // Now lets sort
    DataView dv = new DataView(dt);
    dv.Sort = "Account Type ASC";
    // sort is based on column names specified above.


    Hope that helps,

    Ben Merrills

    "Frank Oquendo" <franko@acadx.com> wrote:
    >Todd Burvee wrote:
    >> Does anyone know of a way to
    >> programatically build a datagrid that sorts? Thanks.

    >
    >Can you show us the code you have so far?
    >
    >--
    >There are 10 kinds of people. Those who understand binary and those who
    >don't.
    >
    >http://code.acadx.com
    >
    >



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center