Sotring in dataView

S

simonZ

I have gridView, which allows sorting and sqlDataSource, which fill in the
data into gridView.
When user clicks one button, I would like to walk through the records in
grid view(which could be sorted):

String content="";
DataSourceSelectArguments arg=new DataSourceSelectArguments();

arg.SortExpression = grdView.SortExpression;
DataView dv = (DataView)SqlDataSource.Select(arg);

foreach (DataRow dr in dv.Table.Rows)
{
content += "<tr><td>"+dr[1].ToString()+"</tD></tr>";
}

It works only that my result(content) is not sorted like gridView. Why? Have
I missed something?

regards,
Simon
 
T

Teemu Keiski

If you sort the DataView, and you want to iterate the results in sorted
order, you'd iterate the dataView, not the DataTable (DataTable's Rows are
always in load order)

Your code should be:

//...
DataView dv = (DataView)SqlDataSource.Select(arg);

//Iterate the DataView
foreach (DataRowView dr in dv)
{
content += "<tr><td>"+dr[1].ToString()+"</tD></tr>";
}
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top