views:

182

answers:

0

Hi have a GridView associated with an XmlDataSource that's structure is dynamic. Essentially, the service that provides the XML simply leaves off an attribute when there's no value, instead of returning an empty value.

This tosses an error and I the rows that come after the one with the missing attribute are not rendered. My issue is that the remaining rows must be rendered. Essentially I want to add the field with a null value so NullDisplayText can handle it.

Here's the XML for the datasource:

<ACTIVITYHISTORYINFO>
<ACTIVITY createStamp="3/10/10 11:00 AM" effectiveDate="3/10/10" name="Cancel Advance" />
<ACTIVITY createStamp="3/9/10 09:43 AM" effectiveDate="3/9/10" name="Funded" description="Offer funded" />
<ACTIVITY createStamp="3/9/10 09:43 AM" effectiveDate="3/9/10" name="E-Signature" description="Signed by Bart Testeropolis" />
<ACTIVITY createStamp="3/9/10 09:38 AM" effectiveDate="3/9/10" name="Approved" description="Offer approved" />

Here's the gridview columns:

<Columns>
<asp:BoundField DataField="createStamp" HeaderText="Date/Time" 
            SortExpression="createStamp" />
<asp:BoundField DataField="effectiveDate" HeaderText="Effective Date" 
            SortExpression="effectiveDate" />
<asp:BoundField DataField="name" HeaderText="Activity" SortExpression="name" />
<asp:BoundField DataField="description" HeaderText="Description" 
            SortExpression="description"  />

And here's the relevant codebehind:

Dim GridView1 As Object = CType(FormView1.FindControl("GridView1"), GridView)
Dim activityHistory As New XmlDataSource()
activityHistory.ID = "activityXmlDataSource"
activityHistory.Data = ectRequest.queryContract(idToQuery)
activityHistory.XPath = "/RESPONSE/ACTIVITYHISTORYINFO/ACTIVITY"
activityHistory.EnableCaching = False
GridView1.DataSource = activityHistory
GridView1.DataBind()

When there is no "description" attribute, as in the first "ACTIVITY" in this example, the following is returned:

System.Web.HttpException: A field or property with the name 'description' was not found on the selected data source.