viola123
asked on
How to sort a numeric field in gridview?
Hi all,
i need to make a numeric field sortable in my gridview.
i did assign a numeric field to my gridview, but when i sort this column, it seems treat it like string:
i need to make a numeric field sortable in my gridview.
i did assign a numeric field to my gridview, but when i sort this column, it seems treat it like string:
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add("No");
ds.Tables.Add(dt);
for (int i = 0; i < dsReview.Tables[0].Rows.Count; i++)
{
DataRow dr = ds.Tables[0].NewRow();
dr["NO"] = i+1; //bind this numeric field and need to sort by this field, but when i found the gridview treat it as a string, how to make it work????
ds.Tables[0].Rows.Add(dr);
}
DataView dv = new DataView(ds.Tables[0]);
dv.Sort = ViewState["SortingField"].ToString() + " " + ((SortDirection)ViewState["SortingDir"] == SortDirection.Ascending ? "ASC" : "DESC");
gvReview.DataSource = dv;
gvReview.DataBind();
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks a lot. it works well.