Hey Guys,
My DataView is acting funny and it is sorting things alphabetically and I need it to sort things numerically. I have looked all across the web for this one and found many ideas on how to sort it with ICompare, but nothing really solid.
So my questions are
- How do I implement ICompare on a DataView (Looking for code here).
- How to correctly decipher from a column full of strings that are actual strings and a column full of numbers(with commas).
I need code to help me out with this one guys. I am more or less lost on the idea of ICompare and how to implement in different scenarios so an over all good explanation would be great.
Also, Please don't hand me links. I am looking for solid answers on this one.
Some Code that I use.
DataView dataView = (DataView)Session["kingdomData"];
dataView.Sort = e.SortExpression + " " + ConvertSortDirectionToSql(e.SortDirection);
gvAllData.DataSource = dataView;
gvAllData.DataBind();
private string ConvertSortDirectionToSql(SortDirection sortDirection)
{
string newSortDirection = String.Empty;
if (Session["SortDirection"] == null)
{
switch (sortDirection)
{
case SortDirection.Ascending:
newSortDirection = "ASC";
break;
case SortDirection.Descending:
newSortDirection = "DESC";
break;
}
}
else
{
newSortDirection = Session["SortDirection"].ToString();
switch (newSortDirection)
{
case "ASC":
newSortDirection = "DESC";
break;
case "DESC":
newSortDirection = "ASC";
break;
}
}
Session["SortDirection"] = newSortDirection;
return newSortDirection;
}