Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 2.0 > ASP.NET 2.0 Basics
Password Reminder
Register
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old November 16th, 2006, 12:02 PM
Authorized User
 
Join Date: Mar 2005
Location: , , .
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>



Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:46 PM.


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