cancel
Showing results for 
Search instead for 
Did you mean: 

how to display the xml content into my datagrid

Former Member
0 Kudos

Hi Experts,

i have created a webservice for sales quotation through DI-Server.iam able to add a new sales quotation through my coding & iam able to get the sales quotation based on the DOcEntry in an *XML file*.

The xml file that i got using DOCENTRY is in this way:--


<?xml version="1.0" encoding="utf-8" ?> 
- <BOM>
- <BO>
- <AdmInfo>
  <Object>oRecordset</Object> 
  </AdmInfo>
- <OQUT>
- <row>
  <DocEntry>8</DocEntry> 
  <DocNum>8</DocNum> 
  <DocDate>20080715</DocDate> 
  <DocDueDate>20080815</DocDueDate> 
  <CardCode>C0003</CardCode> 
  <CardName>HP India</CardName> 
  <DocTotal>14500.000000</DocTotal>
  <ItemCode>A00006</ItemCode> 
  <Dscription>HP Officejet 7310 All-in-One</Dscription> 
  <Quantity>1.000000</Quantity> 
   <Price>14500.000000</Price> 
  <Currency>INR</Currency> 
   <DiscPrcnt>10.000000</DiscPrcnt> 
  <LineTotal>14500.000000</LineTotal> 
   </row>
  </OQUT>
  </BO>
  </BOM>

Now the problem is from this xml content i should display the values in my datagrid like:

DocEntryCardCodeDocDueDateItemCodeDscriptionQtyTotal

8--


C0003
20081116
--A00006-HP-off jet-2 --- 1000

can anybody suggest me some ideas that how to get the SPECIFIED values into my datagrid...........

regards,

shangai.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Try //row or //oqut in stead of //itemcode

Former Member
0 Kudos

Hi vincent van tongeren,

Thanks for your answer "//row" is working absolutely.but the problem is it's displaying only one item (i,e there will be only one item in one row).can u suggest me how to dispaly the multiple rows of item's in my datagrid.

regards,

shangai

Former Member
0 Kudos

hi vincent,

Thanks a lot now iam getting multiple rows from the sales quotation.instead of "
Row" i passed "
OQUT".finally it displayed as row id-0,row id 1.Thanks a lot for ur contribution.i have given u full points

regards,

shangai,

Answers (4)

Answers (4)

Former Member
0 Kudos

Make sure this statement returns nodes:

oQuotationXml.SelectSingleNode("//ItemCode")

Just set a breakpoint on that line of code and watch the variable or put it in the immediate window. My guess is that it returns nothing when this error occurs.

Former Member
0 Kudos

hi vincent,

Yes u are correct.I have kept a breakpoint & checked--DataGrid2.DataSource

this has returned Null value.That's y it's unable to bind to datagrid...now wr's the problem???????

regards,

shangai.

Former Member
0 Kudos

I think this is the error:

replace

Public Sub GetDataSetFromXML(ByVal XmlNode)

by

Public Function GetDataSetFromXML(ByVal XmlNode As XmlNode) As DataSet

You have declared XmlNode AS Object now. And you have created a sub from what was supposed to be a function.

Former Member
0 Kudos

hi vincent,

Thanks a lot now the error was rectified.....now i will check whether iam able to add the sales quotation into my datagrid.

regards,

shangai.

Former Member
0 Kudos

Hi vincent,

When binding the data to datagrid it is displaying the error as

"The IListSource does not contain any data sources"


DataGrid2.DataSource = GetDataSetFromXML(oQuotationXml.SelectSingleNode("//ItemCode"))
*DataGrid2.DataBind()*

regards,

shangai.

Former Member
0 Kudos

Try this function to convert a node to a dataset:

public static DataSet GetDataSetFromXML(XmlNode XMLNode)

{

DataSet ds = new DataSet();

XmlNodeReader reader;

reader = new XmlNodeReader(XMLNode);

ds.ReadXml(reader);

reader.Close();

return ds;

}

Put this in your page:

grid.DataSource = GetDataSetFromXML(Result.SelectSingleNode(xpath_string));

grid.DataBind();

Just to be sure, this is programming question, not a SAP SDK question, so normally this is not the place for these questions

Former Member
0 Kudos

hi vincent,

Thanks for your reply.iam unable to understand these lines in your code..iam working in vb.net


public static DataSet GetDataSetFromXML(XmlNode XMLNode)

&

grid.DataSource = GetDataSetFromXML(Result.SelectSingleNode(xpath_string));

this is my coding....it's throwing an error when i declare like this


Public Sub GetDataSetFromXML(ByVal XmlNode)
        Dim ds As New DataSet
        Dim reader As XmlNodeReader
        reader = New XmlNodeReader(XmlNode)
        ds.ReadXml(reader)
        reader.Close()
        'Return ds --->(error with syntax)
    End Sub


 DataGrid1.DataSource = GetDataSetFromXML(oXmlReply.SelectSingleNode("//DocDueDate"))
            DataGrid1.DataBind()

regards,

shangai

Former Member
0 Kudos

Public Shared Sub GetDataSetFromXML(ByVal XmlNode)

That's the equivalent of 'static' in C#. It's only necessary if this is a method of a class and you want to use it without instantiating a new object. You should probably keep it the way it is.

Could you post the error that line is giving you? It could be your XML is not correct?

Former Member
0 Kudos

Hi vincent,


GetDataSetFromXML(oXmlReply.SelectSingleNode("\\DocDueDate"))

the whole line is underlined & is saying "Expression doesn't prduce any value"

regards,

shangai.

Former Member
0 Kudos

There is few ways how to achieve it:

1. Fill the matrix cell by cell (i think that matrix is better than grid for this)

2. Bind matrix to datatable and fill the datatable with your xml (only row part of xml) - datatable.LoadFromXML

3. Parse the xml and insert the values you need into user table and this table bind to matrix

Former Member
0 Kudos

hi peter,

Iam using Visual studio 2003...so i don't have an option of matrix in my asp.net application.

regards,

shangai.