I have a problem yet I can't seem to find any examples online to help me overcome it. It should be dead simple! I am converting scripts written in asp to asp.net 2.0. I have managed to work out most issues however using the C# syntax I do not know how to loop through the contents of a database field called Centre. This is a college website made up of both academic and support departments. You can search for a course in each department, however what I want it to do is to display the centres of the departments and then carry out a search in a further page. For example Business and Management, has two Centres, Business plus Education Management. The problem is when I go to the "Search by Centre" page it is only throwing up a field for Business and ignores the other entry. Some departments have up to 10 centres.
In classic asp I would have gotten round this by using something like the following code.
Code:
<% If (Not(rstList.EOF)) Then
Do Until rstList.EOF
%>
<% Set rstCentres = cnnPMan.execute("SELECT Centre FROM Centres WHERE Department_id = Request.QueryString("departmentid")"; %>
<%
<% Response.Write(rstCentre.Fields.Item("Centre ") & " " & rstCentre.Fields.Item("Department_id").Value) %>
</a></p>
</li>
</ul>
</td>
</tr>
<% rstList.MoveNext()
In asp.net 2.0 c# I don't know what to create. I am not looking for anyone to do it for me but if anyone has any advice to put me in the right direction it would be a huge help.
This is what I have come up with which only prints the one entry.
Code:
<%@ Register TagPrefix="BIE" TagName="header" Src="header.ascx" %>
<%@ Register TagPrefix="BIE" TagName="footer" Src="footer.ascx" %>
<%@ Page Language="C#" Theme="Gridview" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">
public void Page_Load(object sender, System.EventArgs e)
{
if (Request.QueryString["department_id"] != null)
{
Label1.Text = Request.QueryString["department_id"];
}
}
</script>
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Centres</title>
<link href="incs/Style.css" media="screen" rel="stylesheet" title="Style" type="text/css" />
<link href="incs/Style.css" media="screen" rel="stylesheet" title="Style" type="text/css" />
<link href="incs/Style.css" media="screen" rel="stylesheet" title="Style" type="text/css" />
<link href="incs/Style.css" media="screen" rel="stylesheet" title="Style" type="text/css" />
</head>
<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td colspan="3">
<BIE:HEADER id="header1" Runat="server"></BIE:HEADER>
</td>
</tr>
<tr>
<td colspan="3">
<h3>Search by Department</h3>
<asp:AccessDataSource ID="AccessDataSource1" runat="server" DataFile="~/courses.mdb"
SelectCommand="SELECT [Centre] FROM [Centres] WHERE Department_id = @department_id">
<SelectParameters>
<asp:ControlParameter ControlID="Label1" Name="department_id" PropertyName="Text" Type="String" />
</SelectParameters>
</asp:AccessDataSource>
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label><br />
<br />
<asp:FormView ID="FormView1" runat="server" DataSourceID="AccessDataSource1" EnableViewState="False">
<ItemTemplate>
<table>
<tr>
<td><h3></h3></td>
</tr>
<tr>
<td><h3><%# Eval("Centre")%></h3></td>
</tr>
</table>
</ItemTemplate>
</asp:FormView>
</tr>
<tr>
<td colspan="3">
<BIE:FOOTER id="footer1" Runat="server"></BIE:FOOTER>
</td>
</tr>
</table>
</div>
</form>
</body>
</html>