Gridview not sorting numeric or fomating because of datatype

C

Cindy Lee

I get my data from a basic xml file and make a datatable, and then bind it
to the gridview. I think it's not sorting or dataformatString correctly
because it thinks it's a string and not a number. Is there a way to tell
the gridview the value is a int?

This is how I bind the data:
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(new StringReader(xmlString));
DataTable table = aDataSet.Tables[0];
GridView1.DataSource = table;
GridView1.AllowSorting = true;
GridView1.DataBind();

Here is a bound field:
<asp:BoundField DataField="percentage" HeaderText="%"
SortExpression="percentage" HtmlEncode="False" DataFormatString="{0:p2}"
ReadOnly="True" />

All my value colums are sorted alphabetical
 
C

Cindy Lee

Oh, sorry. I do the sorting manually because it comes from an XML file.
But I still can't get the formatting to work. I guess I can fix it in the
XML file.
 
C

Cindy Lee

This is my sorting function. How can I sort it numerically?
if (isPageIndexChanging)
{

dataView.Sort = string.Format("{0} {1}",
GridViewSortExpression, GridViewSortDirection);

}

else
{

dataView.Sort = string.Format("{0} {1}",
GridViewSortExpression, GetSortDirection());

}

Cindy Lee said:
Oh, sorry. I do the sorting manually because it comes from an XML file.
But I still can't get the formatting to work. I guess I can fix it in the
XML file.
Cindy Lee said:
I get my data from a basic xml file and make a datatable, and then bind it
to the gridview. I think it's not sorting or dataformatString correctly
because it thinks it's a string and not a number. Is there a way to tell
the gridview the value is a int?

This is how I bind the data:
DataSet aDataSet = new DataSet();
aDataSet.ReadXml(new StringReader(xmlString));
DataTable table = aDataSet.Tables[0];
GridView1.DataSource = table;
GridView1.AllowSorting = true;
GridView1.DataBind();

Here is a bound field:
<asp:BoundField DataField="percentage" HeaderText="%"
SortExpression="percentage" HtmlEncode="False" DataFormatString="{0:p2}"
ReadOnly="True" />

All my value colums are sorted alphabetical
 

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

Top