Sotring in dataView

  • Thread starter Thread starter simonZ
  • Start date Start date
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
 
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>";
}
 
Back
Top