Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

asp:dropdownlist 1

Status
Not open for further replies.

LindaH

Programmer
Dec 12, 2001
42
US
Instead of populating the Items Collection of a DropDownList, I coded my HTML page like this:[ul]<asp:dropdownlist id=ddlMailState runat=&quot;server&quot;>
<!--#include file=&quot;includes/states.inc&quot;-->
</asp:dropdownlist>[/ul]
where the include file looked like this:[ul]<asp:ListItem>AL</asp:ListItem>
<asp:ListItem>AK</asp:ListItem>
<asp:ListItem>AZ</asp:ListItem>

and so on.[/ul]
When I run the application, the dropdownlist works as expected, but in design view, I get an &quot;Error Creating Control&quot; message on my control and can no longer access its properties. When I hover over the control, the error message reads, &quot;Parser Error: Value cannot be null. Parameter name: path1.&quot;

Does anyone know of a way to use an include file as a source for the Items Collection without getting this error? I don't want to put the State codes in a database and bind the control to the DataSource as there's no need to make a trip to the database for something as simple as this.

Thanks.
 
well, I have a way for you to be able to load the options from a file instead of a db, but it's a little more complicated than just using an include file (but it'll be more rewarding since it deals with new technology).

is a link to an article that details how you can read in an xml file to your code and dynamically fill the ddl from there. It's really not that hard, and the example the author gives is very easy to understand and duplicate.

Something to consider anyway
:)

Jack
 
This is a great solution!

Now I'm having a problem with the path I specify in the ds.ReadXml() command. I've included the relative path name (much like I did in the INCLUDE), but it interprets the path as &quot;c:\winnt\system32\includes\XMLStates.xml&quot;

Here's the code I'm using:[ul]Imports System.Web.UI.WebControls
Imports System.Data
Imports System.Xml
Imports System.Xml.XPath
Imports System.Xml.Xsl
Imports System.IO
[/ul]My Page_Load event calls the following subroutine:[ul]Private Sub BindStateCodes()
Dim dsStates as New DataSet

dsStates.ReadXml(&quot;includes/XMLStates.xml&quot;)
ddlMailState.DataSource = dsStates.Tables(0)
ddlMailState.DataTextField = dsStates.Tables(0).Columns(0).ToString()
ddlMailState.DataValueField = dsStates.Tables(0).Columns(1).ToString()
ddlMailState.DataBind
End Sub[/ul]
Any ideas?
 
I found the problem. Code BindStateCodes like this: [ul]Private Sub BindStateCodes()
Dim dsStates as New DataSet
Dim sPath as String
sPath = Server.MapPath(&quot;includes\XMLStates.xml&quot;)

dsStates.ReadXml(sPath)

ddlMailState.DataSource = dsStates.Tables(0)
ddlMailState.DataTextField = dsStates.Tables(0).Columns(0).ToString()
ddlMailState.DataValueField = dsStates.Tables(0).Columns(1).ToString()
ddlMailState.DataBind
End Sub[/ul]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top