Solved

c# asp.net databind() xml to gridview

Posted on 2010-08-23
4
438 Views
Last Modified: 2013-11-07
i have the below code. it is returning xml data back from the stored poc in the form:
<row ProjectMilestoneId="2" ProjectId="2" MilestoneCID="1" MilestoneText="High" StartDate="1933-05-16T00:00:00" EndDate="2033-01-01T00:00:00" RAGStatusCID="7" RAGStatusText="Red                                               " CompletionStatusCID="33" CompletionStatusText="Delayed                                           " StatusText="testing text11111" Added="2010-08-23T15:06:52.580" LastUpdate="2010-08-23T15:06:52.580" UpdateBy="mshinder" />
<row ProjectMilestoneId="3" ProjectId="2" MilestoneCID="1" MilestoneText="High" StartDate="1933-05-16T00:00:00" EndDate="2033-01-01T00:00:00" RAGStatusCID="7" RAGStatusText="Red                                               " CompletionStatusCID="33" CompletionStatusText="Delayed                                           " StatusText="testing text11111" Added="2010-08-23T15:06:54.707" LastUpdate="2010-08-23T15:06:54.707" UpdateBy="mshinder" />
<row ProjectMilestoneId="4" ProjectId="2" MilestoneCID="1" MilestoneText="High" StartDate="1933-05-16T00:00:00" EndDate="2033-01-01T00:00:00" RAGStatusCID="7" RAGStatusText="Red                                               " CompletionStatusCID="33" CompletionStatusText="Delayed                                           " StatusText="testing text11111" Added="2010-08-23T15:06:54.910" LastUpdate="2010-08-23T15:06:54.910" UpdateBy="mshinder" />
<row ProjectMilestoneId="5" ProjectId="2" MilestoneCID="1" MilestoneText="High" StartDate="1933-05-16T00:00:00" EndDate="2033-01-01T00:00:00" RAGStatusCID="7" RAGStatusText="Red                                               " CompletionStatusCID="33" CompletionStatusText="Delayed                                           " StatusText="testing text11111" Added="2010-08-23T15:06:55.127" LastUpdate="2010-08-23T15:06:55.127" UpdateBy="mshinder" />
XmlReader xr = cmd.ExecuteXmlReader();
DataSet ds2 = new DataSet();
ds2.ReadXml(xr, XmlReadMode.InferSchema);
if (xr != null) xr.Close();
            
DataView myDataView = ds2.Tables[0].DefaultView;

if (sortExp != string.Empty)
                myDataView.Sort = string.Format("{0} {1}", sortExp, sortDir);

gvMilestone.DataSource = myDataView;
gvMilestone.DataBind();

Open in new window

0
Comment
Question by:realcoding
  • 2
4 Comments
 
LVL 35

Expert Comment

by:YZlat
ID: 33504509
what is the issue with your code?
0
 
LVL 10

Expert Comment

by:Jini Jose
ID: 33504606
0
 

Author Comment

by:realcoding
ID: 33504667
gmailjini: sorry way off base.

my code has an index out of range exception in the line:
DataView myDataView = ds2.Tables[0].DefaultView;

0
 

Accepted Solution

by:
realcoding earned 0 total points
ID: 33561864
the xml should be in format of for xml raw not for xml auto. this does the trick.
0

Featured Post

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question