Wrox Programmer Forums
Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old November 16th, 2006, 12:02 PM
Authorized User
 
Join Date: Mar 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts
Default Field problem (requires c# do loop)

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 ") & "&nbsp;" & 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>








Similar Threads
Thread Thread Starter Forum Replies Last Post
Have a problem in For-each loop LeoMathew XSLT 2 July 16th, 2008 05:20 AM
For Each Field loop syedferhat Classic ASP Professional 0 December 19th, 2007 02:08 AM
VS 2005 Problem: project requires a unique name. EugenX Visual Studio 2005 1 September 7th, 2006 09:15 AM
while loop problem shoakat Classic ASP Databases 1 September 21st, 2004 03:44 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.