sorting grid

  • Thread starter Thread starter Nikhil Patel
  • Start date Start date
N

Nikhil Patel

Hi all,
I have written an ASP.Net form that displays a sortable grid. I works
fine in Internet Explorer. But it gives me an error when I try to display it
in 3rd party application. The error says something like "object expected" in
the following line:
<td nowrap="nowrap"><a
href="javascript:__doPostBack('dgProposals$_ctl1$_ctl0','')"
style="color:White;">ProposalID</a></td>
Please note that in the above line dgProposals is the grid's name and
ProposalID is the header text for a sortable column of the grid.
I think this line is the header of the sortable column. I know that the
third party application does sopport Javascript. So the question is that is
the above line actually Javascript. Is there any other way to sort the grid
so that it works in the 3rd party application that supports HTML and
Javascript?

Please help.

Thanks...
-Nikhil
 
Nikhil,
You can deligate a method to handle Datagrid's sort command event. In the
method, you will sort the data before binding it to the grid. See the code
snippet below:

Private var to keep track of the sortstring:
private static string SortExpression="";

Deligate:
this.dgTest.SortCommand += new
System.Web.UI.WebControls.DataGridSortCommandEventHandler(this.dgTest_Sort);

Method:
void dgTest_Sort(Object sender, DataGridSortCommandEventArgs e)
{
if(SortExpression==e.SortExpression.ToString()) //Change the sort order
to DESC
{
SortExpression = e.SortExpression.ToString() +" DESC";
}
else //Change the sort order to ASC
{
SortExpression = e.SortExpression.ToString();
}

try
{
DataTable dtTest=Get your DataTable here;
//datasoure will be the DefaultView of dtTest Table.
DataView dv=dtTest.DefaultView;

//Sort the DataView
if (SortExpression !="")
{
dv.Sort=SortExpression;
}
dgTest.DataBind();
}
catch(Exception ex)
{
throw ex;
}

}

Good luck :)-
Prodip Saha
 
Back
Top