DataBind Problem

  • Thread starter Thread starter JV
  • Start date Start date
J

JV

You could preload it using XmlDocument and see if it has the nodes you are
expecting.

"Chris Kennedy" <[email protected]> I have a drop down list,
which binds to dataset based on an XML file like the one below.
The databind routine can't find any columns and hence throws an error. Is
there a straight forward way to test for this an then not bind?
 
Could you give us a pointer in code as I am al ittle new to XML. Would a
node list in Xpath do the job?
My approach - you say that you already have a DataSet from the XML (via
ReadXML() method). Look in the properties of the DataSet (for example
Tables gives you the tables collection); from this you can infer whether
dataset is empty and prevent the Bind.
 
I have a drop down list, which binds to dataset based on an XML file like the one below.

<xmlform>
<formelement id="0">
<maxlength>234</maxlength>
<datatype>String</datatype>
<isnull>true</isnull>
<index>0</index>
</formelement>
</xmlform>

Sometime the XML will have nothing in it like so

<xmlform>
</xmlform>

The databind routine can't find any columns and hence throws an error. Is there a straight forward way to test for this an then not bind?
 
Could you give us a pointer in code as I am al ittle new to XML. Would a
node list in Xpath do the job?
 
Or, of course, you could use a Try..Except block, and trap the error
that gets thown when the list is empty...

Cheers,
zdrakec
 
Chris,

please fix your system date.

You're future posting.



Juan T. Llibre
ASP.NET MVP
http://asp.net.do/foros/
Foros de ASP.NET en Español
Ven, y hablemos de ASP.NET...
======================
 
I tried doing a table count but could get it to work.I did this instead, it
works although I am sure you could something with less lines of code.

Function nodecount() As Integer
xmldoc = Session("xmldoc")
Dim intnodecount As Integer = 0
xmllist = xmldoc.GetElementsByTagName("formelement")
For Each xmlnode In xmllist
intnodecount = intnodecount + 1
Next
If intnodecount = 0 Then
lbltest.Text = "XML Config File is empty"
End If
Return intnodecount
End Function
That works, but int the future just get Tables.length.
 
I tried doing a table count but could get it to work.I did this instead, it
works although I am sure you could something with less lines of code.

Function nodecount() As Integer
xmldoc = Session("xmldoc")
Dim intnodecount As Integer = 0
xmllist = xmldoc.GetElementsByTagName("formelement")
For Each xmlnode In xmllist
intnodecount = intnodecount + 1
Next
If intnodecount = 0 Then
lbltest.Text = "XML Config File is empty"
End If
Return intnodecount
End Function
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top