H
hb
Hi,
I use the "FOR XML AUTO,ELEMENTS" to get data from SQL server database:
string x=getProductListFromSql();
The xml scheme of x like:
<list>
<Product>
<productID>234</productID>
<productName>light</productName>
</Product>
<Product>
<productID>235</productID>
<productName>light bulb</productName>
</Product>
</list>
Then, I use the following code to bind data to datagrid:
public void BindData()
{
DataSet ds = new DataSet();
XmlDocument doc = new XmlDocument();
doc.LoadXml(x);
XmlNodeReader xnr = new XmlNodeReader(doc);
ds.ReadXml(xnr);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
The sorting function is like:
public void sortDG(object sender, DataGridSortCommandEventArgs e)
{
string sortKey = e.SortExpression;
Session["sortKey"] = sortKey;
BindData();
}
In DataGrid1, the boundcolumn like:
<asp:boundcolumn data="productID" sortexpression="productID"
headertext="ProductID" />
But I get a problem here: the sort function treats the "productID" as string
instead of integer.
I guess the cause is that I transferred data into xml string. Then all data
become string data type.
Please help me: How can I let the sorting function recognize "productID" as
integer?
Thank you
hb
I use the "FOR XML AUTO,ELEMENTS" to get data from SQL server database:
string x=getProductListFromSql();
The xml scheme of x like:
<list>
<Product>
<productID>234</productID>
<productName>light</productName>
</Product>
<Product>
<productID>235</productID>
<productName>light bulb</productName>
</Product>
</list>
Then, I use the following code to bind data to datagrid:
public void BindData()
{
DataSet ds = new DataSet();
XmlDocument doc = new XmlDocument();
doc.LoadXml(x);
XmlNodeReader xnr = new XmlNodeReader(doc);
ds.ReadXml(xnr);
DataGrid1.DataSource = ds;
DataGrid1.DataBind();
}
The sorting function is like:
public void sortDG(object sender, DataGridSortCommandEventArgs e)
{
string sortKey = e.SortExpression;
Session["sortKey"] = sortKey;
BindData();
}
In DataGrid1, the boundcolumn like:
<asp:boundcolumn data="productID" sortexpression="productID"
headertext="ProductID" />
But I get a problem here: the sort function treats the "productID" as string
instead of integer.
I guess the cause is that I transferred data into xml string. Then all data
become string data type.
Please help me: How can I let the sorting function recognize "productID" as
integer?
Thank you
hb