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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

convert to DropDownList 1

Status
Not open for further replies.

A1Pat

IS-IT--Management
Jun 7, 2004
454
US
hi all,

I'm doing this exercise displaying data from XML table to DataListControl

Code:
<%@ Import Namespace="System.Data" %>
<html>
<head>
<title>Sample Page using VB.NET</title>
<script runat="server" language="VB">
Sub Page_Load
if Not Page.IsPostBack then
	'load XML file to DataSet'
	dim myCars=New DataSet
	myCars.ReadXml (MapPath("cars2.xml"))
	'bind the myCars DataSet to the Repeater control'
	cars.DataSource=myCars
	cars.DataBind()
end if
End Sub
</script>
</head>

<body>
<form runat="server">
	<asp:DataList ID="cars" runat="server" CellPadding="2" CellSpacing="2" BackColor="#CCCCCC" Width="80%" HeaderStyle-Font-Name="Verdana" HeaderStyle-Font-Size="12pt" HeaderStyle-HorizontalAlign="center" HeaderStyle-Font-Bold="true" ItemStyle-BackColor="#0099CC" ItemStyle-ForeColor="#FFFFFF" AlternatingItemStyle-BackColor="#CC9933" AlternatingItemStyle-ForeColor="#000000" FooterStyle-Font-Size="9pt" FooterStyle-Font-Italic="true" FooterStyle-HorizontalAlign="right">
		<headertemplate>
		My Car Catalog
		</headertemplate>
		
		<itemtemplate>
		<%#Container.DataItem("year")%> <%#Container.DataItem("manufacturer")%> <%#Container.DataItem("model")%>
		</itemtemplate>
		
		<alternatingitemtemplate>
		<%#Container.DataItem("year")%> <%#Container.DataItem("manufacturer")%> <%#Container.DataItem("model")%>
		</alternatingitemtemplate>
 
 		<footertemplate>
		&copy; Patrick Huynh
		</footertemplate>
	</asp:DataList>
</form>
</body>
</html>

Now, I'd like to display the results to a DropDownList instead, and couldn't find an similar example anywhere. Can someone help me see a way!
 
Add a DropDownList to your page, set it's DataSource to the DataSet and call the DataBind method. You will also have to set the DataTextField and DataValueField to their relevant columns.


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
I'm sorry Mark,

Could you be more specific or provide some short example for a better clarification?

What I mean is
1/Is the Drop Down List located within itemtemplate or any else where?
2/Drop Down List I learned so far includes ListItem, how should I modify the ListItem to display the data?

Sorry about the very "beginner" questions...
 
Get rid of the DataList from your page and add a DropDownList. Then, on the page load event set these properties:
Code:
    MyDropDownList.DataSource=myCars
    MyDropDownList.DataTextField = "column name goes here"
    MyDropDownList.DataValueField = "column name goes here"
    MyDropDownList.DataBind()


____________________________________________________________
Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]

Need help finding an answer? Try the Search Facility or read FAQ222-2244 on how to get better results.
 
AHA!!!!

Great help!

Thank you very much Mark... keep up the good work!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top