Ask a Question related to ASP.NET Data Grid Control, Design and Development.
-
hb #1
Help: sorting problem on data type?
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
hb Guest
-
Converting from data type varchar to data type money
Hi all, Tearing my hair out trying to figure this out. If anyone can provide any help i would greatly appreciate it. When I try to do an insert... -
Converting data type varchar to data type money
Hi all, Tearing my hair out trying to figure this out. If anyone can provide any help i would greatly appreciate it. When I try to do an insert... -
ASP.NET Sorting data
I am creating a web application (ASP.NET) to store contact details of all staff etc. I am able to pull all the data out of my sql database and... -
Sorting and data
Hey, I have a datagrid, which has sorting enabled. Now whenever I sort the datagrid, then the first few lines in the datagrid, doesnt show the... -
Sorting by Data
Hi, I currently have a Transactions form that outputs, in continuous form view, all of the transactions for a given contact. I would like to... -
Lewis Wang [MSFT] #2
RE: Help: sorting problem on data type?
Hi Hb,
We can create a new DataTable and define every column Type for it. Expect
the productID column whose type is int32, other columns' types are the same
as the old DataTable. Then we could copy all data from the old DataTable to
the new DataTable and bind the new DataTable to DataGrid1.
DataTable newtable=new DataTable ();
DataColumn cc1 = new DataColumn("productID ",
Type.GetType("System.Int32"),"");
c1.AutoIncrement=true;
DataColumn cc2 = new DataColumn("Item", Type.GetType("System.String"),"");
newtable.Columns.Add(cc1);
newtable.Columns.Add(cc2);
for(int i=0; i<t.Rows.Count;i++)
{
DataRow dr=newtable.NewRow ();
for(int j=0;j<t.Columns .Count;j++)
dr[j]=t.Rows[i][j];
newtable.Rows .Add(dr);
}
//Note: t is the old table, its " productID " column Type is String.
Hope this helps.
Best regards,
Lewis
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
| From: "hb" <hongbo@goodoffices.com>
| Subject: Help: sorting problem on data type?
| Date: Thu, 4 Sep 2003 18:25:35 -0400
| Lines: 70
| X-Priority: 3
| X-MSMail-Priority: Normal
| X-Newsreader: Microsoft Outlook Express 6.00.2800.1158
| X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165
| Message-ID: <ODED9NzcDHA.1656@TK2MSFTNGP10.phx.gbl>
| Newsgroups: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
| NNTP-Posting-Host: x403446fe.ip.e-nt.net 64.52.70.254
| Path: cpmsftngxa06.phx.gbl!TK2MSFTNGP08.phx.gbl!TK2MSFTN GP10.phx.gbl
| Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.aspnet.datagridc ontrol:6506
| X-Tomcat-NG: microsoft.public.dotnet.framework.aspnet.datagridc ontrol
|
| 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
|
|
|
Lewis Wang [MSFT] Guest



Reply With Quote

