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

Displaying values in xml file asp.net

Status
Not open for further replies.

d1novak

Instructor
Jul 21, 2003
27
US
Hi all,
I have an xml file that displays class dates (Day 1 and Day2). I have sucessfully populated the dropdownlist1 with the Day1 Data. I want to add onselectedchanged to the dropdownlist1 to run another sub procedure that will return the value of day2 for the selected record.
Then bind it to a label.
below is the xml file and the aspx page


<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<dataroot xmlns:xsi=" <Class>
<Day1>Access 2003 Level - 1 03/05/08</Day1>
<Day2>03/07/08</Day2>
</Class>
<Class>
<Day1>Access 2003 Level 2 - 03/24/08</Day1>
<Day2>03/31/08</Day2>
</Class>
</dataroot>

----------------------------------------------------------

<%@ Import Namespace="System.Data" %><script runat="server">

sub Page_Load
if Not Page.IsPostBack then
dim myclasses=New DataSet
myclasses.ReadXml(MapPath("classes.xml"))
DropDownList1.DataSource = myclasses
DropDownList1.DataTextField = "Day1"
DropDownList1.DataValueField = "Day1"
DropDownList1.DataBind()
End if
end sub

</script>
<html>
<body><form runat="server">

Instructor Led Class: <asp:DropDownList id="DropDownList1" runat="server"></asp:DropDownList>

</form>

</body>
</html>

I want to add onselectedchanged to the dropdownlist1 to run another sub procedure that will return the value of day2 for the selectedrecord.
Then bind it to a lable.

Stumped...
any help is greatly appreciated

thank you
 
I want to add onselectedchanged to the dropdownlist1 to run another sub procedure that will return the value of day2
Ok, so exactly which bits of this are you having trouble with? What have you tried?


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
I added this to the script area.

sub displayGrid(s as Object,e As EventArgs)
Dim myDataSet1 = New DataSet
myDataSet1.ReadXml(Server.MapPath("classes.xml"))
Dim table as DataTable = myDataset1.Tables(0)
Dim rows as DataRow() = table.Select( "Day1 = & DropDownList1.text'")
lbl1.text=ToText(rows(1))
End Sub

Then in the html section I added the OnSelectedChanged="displayGrid" to the DropDownList1 tag

<asp:label id="lbl1" runat="server"></asp:label>

I thought mabey I was taking the wrong approch
 
Here is the whole page:
I am trying to use DataRow
the error is:
Compiler Error Message: BC30311: Value of type 'System.Data.DataRow' cannot be converted to 'String'

<%@ Import Namespace="System.Data" %><script runat="server">

sub Page_Load
if Not Page.IsPostBack then
dim myclasses=New DataSet
myclasses.ReadXml(MapPath("classes.xml"))
DropDownList1.DataSource = myclasses
DropDownList1.DataTextField = "Day1"
DropDownList1.DataValueField = "Day1"
DropDownList1.DataBind()
End if
end sub
sub displayGrid(s as Object,e As EventArgs)
Dim myDataSet1 = New DataSet
myDataSet1.ReadXml(Server.MapPath("classes.xml"))
Dim table as DataTable = myDataset1.Tables(0)
Dim rows as DataRow() = table.Select( "Day1 = '& DropDownList1.Text &'")
lbl1.text=rows(1)
End Sub
</script>
<html>
<body><form runat="server">

Instructor Led Class: <asp:DropDownList id="DropDownList1" runat="server" OnSelectedChanged="displayGrid"></asp:DropDownList><P>
Day2:<asp:label id="lbl1" runat="server"></asp:label>
</form>

</body>
</html>
 
Your syntax here is wrong:
Code:
Dim rows as DataRow() = table.Select( "Day1 = '& DropDownList1.Text &'")

Try:
Code:
Dim rows as DataRow() = table.Select( "Day1 = '" & DropDownList1.SelectedText & '")
 
It threw an error "SelectedText is not a member of the DropDownList
 
Thank you all for your help.
I figured it out, I was missing a " near the end.

Dim rows as DataRow() = table.Select( "Day1 = '& DropDownList1.Text & "'")
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top