ASP.net - More Problems :D

trewyn15

New Member
Hey guys, I have some more problems here :P

Working on an ASP.net project, having trouble calculating information out of my ListBox and getting issues with the location of my script.

Here is what I have so far for my code:

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<script runat="server">
	protected void btnButton1_Click(object sender, EventArgs e)
	{
		foreach (ListItem item in ListBox1.Items)
		
		Label1.Text="Text Output";
	}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Lab 7</title>
</head>

<body>

<form id="form1" runat="server">
	<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyDocs\Desktop\DBSAMPLE.mdb" ProviderName="System.Data.OleDb" SelectCommand="SELECT [TicketPrice] FROM [Airplane - Seat Locations]">
	</asp:SqlDataSource>
	<br />
	<asp:ListBox id="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="TicketPrice" DataValueField="TicketPrice">
	</asp:ListBox>
	<br />
	<asp:Button id="btnButton1" runat="server" Text="COMPUTE COST" OnClick="Button1_Click" />
	<br />
	<br />
	<asp:Label id="Label1" runat="server" Text="Label"></asp:Label>
</form>

</body>

</html>

and here is what's being asked of me:

1. Display the cost of all air seats in a ListBox
2. Click the COMPUTE COST button to show the total cost of all seats in a Label.
3. 3. Read the DBSAMPLE.mdb Access database , Airplane – Seat Locations data table using a web config file

So all of the air seats are being pulled from the DBSAMPLE database file and displayed in the listbox, I have those displaying fine, but I am having a hard time understanding how I can take those and put them into an equation to get the total cost of all the seats and display that number in the label that I have already created.

#3 also, I just don't understand what's being asked there lol

Any help is appreciated a usual!
 
I don't really understand what you are being asked for in #2. If it's just a sum of the cost of each seat in the database then it's trivial.

For #3, I think it's asking you to read a file for the database location, credentials, etc. but I'm not 100% sure. You'll have to ask for clarification.
 
I don't really understand what you are being asked for in #2. If it's just a sum of the cost of each seat in the database then it's trivial.

For #3, I think it's asking you to read a file for the database location, credentials, etc. but I'm not 100% sure. You'll have to ask for clarification.

I almost think #3 is asking to use that database for the rest of the program? Not 100% sure either lol

For number two, I just don't understand how to take the sum of those files into the database, the output shouldn't be the hard part. Putting in the equation just confuses me slightly.
 
I've worked some more, but getting a problem with the script runat, script is underlined in red.

Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<%@ Page Language="C#" %>

<script runat="server">
	protected void btnButton1_Click(object sender, EventArgs e)
	{
	int totalPrice = 0;
	
	foreach (ListItem item in ListBox1.Items)
	{
		totalPrice += Convert.ToInt32(item.Value);
	}
	
	Label1.Text = totalPrice;
	}
</script>

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Lab 7</title>
</head>

<body>

<form id="form1" runat="server">
	<asp:SqlDataSource id="SqlDataSource1" runat="server" ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\MyDocs\Desktop\DBSAMPLE.mdb" ProviderName="System.Data.OleDb" SelectCommand="SELECT [TicketPrice] FROM [Airplane - Seat Locations]">
	</asp:SqlDataSource>
	<br />
	<asp:ListBox id="ListBox1" runat="server" DataSourceID="SqlDataSource1" DataTextField="TicketPrice" DataValueField="TicketPrice">
	</asp:ListBox>
	<br />
	<br />
	<asp:Button id="btnButton1" runat="server" Text="COMPUTE COST" OnClick="Button1_Click" />
	<br />
	<br />
	<asp:Label id="Label1" runat="server" Text="Label"></asp:Label>
</form>

</body>

</html>

Getting there I think :D
 
Back
Top