how to save the sorted dataview in a datatable

A

Anna Schmidt

Hello,

I have a datatable, that it sorted in a dataview, works fine.

but i want to pass that sorted datatable to another methods (for formatting)

It doesn't work with dataview.table (only the original datatable is
passed)

DataTable dt = GetDT();

DataView dv = new DataView(dt);

dv.Sort = sortExpression;

formatDataTable(dv.Table); // no sorting



Thank you



anna
 
A

Anna Schmidt

thank you!
I'll try it now.

since i have so many different datagrids, i create and format datagrids (on
the fly) without any formatting in the aspx.file..
for example I translate some flag-fields in corresponding messages, or have
different time-formatting methods (short date, long date,...) depending on
the aggregation level..
so i just send all my datatable to a kind of "generic" method that formats
the fields, so no aspx file is required..
do you have any better idea?
thank you

anna

Suresh said:
May be not the most efficient way..

You clone the original datatable structure and then iterate thru the
dataview to insert the sorted records into the new DataTable (see sample
below).
What kind of formatting are you doing? If it's formatting for the UI then
you should consider formatting the data in your aspx page and not at the
datasource/datatable level.
(i.e. In C#)

DataView newDV = myDataTable.DefaultView;
newDV.Sort = "FirstName ASC";

DataTable tbNew = myDataTable.Clone();
tbNew.Clear();

for (int i=0; i< newDV.Table.Rows.Count; i++)
{
DataRow tbRow = tbNew.NewRow();
tbRow.BeginEdit();
DataRow dr = newDV.Row;

foreach(DataColumn dc in tbNew.Columns)
{
tbRow[dc.ColumnName] = dr[dc.ColumnName].ToString().Trim();
}

tbRow.EndEdit();
tbNew.Rows.Add(tbRow);
}
tbNew.AcceptChanges();

HTH,
Suresh.

----- Anna Schmidt wrote: -----

Hello,

I have a datatable, that it sorted in a dataview, works fine.

but i want to pass that sorted datatable to another methods (for formatting)

It doesn't work with dataview.table (only the original datatable is
passed)

DataTable dt = GetDT();

DataView dv = new DataView(dt);

dv.Sort = sortExpression;

formatDataTable(dv.Table); // no sorting



Thank you



anna
 
G

Guest

I translate some flag-fields in corresponding messages, or have different time-formatting methods (short date, long date,...) depending on the aggregation level.
so i just send all my datatable to a kind of "generic" method that formats the fields, so no aspx file is required.

Hmmm..
You can set the formatting of the columns from the code behind as well
So instead of sending the datatable to a generic function to be formatted can you call a generic function that sets the formatting of the columns based on your aggregation level?

Suresh

----- Anna Schmidt wrote: ----

thank you
I'll try it now

since i have so many different datagrids, i create and format datagrids (o
the fly) without any formatting in the aspx.file.
for example I translate some flag-fields in corresponding messages, or hav
different time-formatting methods (short date, long date,...) depending o
the aggregation level.
so i just send all my datatable to a kind of "generic" method that format
the fields, so no aspx file is required.
do you have any better idea
thank yo

ann

Suresh said:
May be not the most efficient way.
dataview to insert the sorted records into the new DataTable (see sampl
below)you should consider formatting the data in your aspx page and not at th
datasource/datatable level
(i.e. In C#
DataView newDV = myDataTable.DefaultView newDV.Sort = "FirstName ASC"
DataTable tbNew = myDataTable.Clone() tbNew.Clear()
for (int i=0; i< newDV.Table.Rows.Count; i++

DataRow tbRow = tbNew.NewRow()
tbRow.BeginEdit()
DataRow dr = newDV.Row
foreach(DataColumn dc in tbNew.Columns

tbRow[dc.ColumnName] = dr[dc.ColumnName].ToString().Trim()
tbRow.EndEdit() tbNew.Rows.Add(tbRow)

tbNew.AcceptChanges()
Suresh
----- Anna Schmidt wrote: ----
Hello
I have a datatable, that it sorted in a dataview, works fine
but i want to pass that sorted datatable to another methods (fo formatting
It doesn't work with dataview.table (only the original datatable i passed
DataTable dt = GetDT()
DataView dv = new DataView(dt)
dv.Sort = sortExpression
formatDataTable(dv.Table); // no sortin
 

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

Top