Newby Question

Discussion in 'C#' started by RuthlessRoth, May 1, 2009.

  1. #1
    I'm just getting started with ASP.
    I want to add the Alphabet A to Z for
    prospect look ups
    If A is clicked on the it will show all the prospects that start with A
    Then if they click on one of those prospects it will open a new window
    so they can edit any of those fields

    First I would like to start with the look up.
    ANY help would be greatly appreciated. I did take a 9 week course
    so I have been playing with ASP.NET 3.5

    Thanks
     
    RuthlessRoth, May 1, 2009 IP
  2. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #2
    Here's something to get you started, coded with ASP.NET. The followin is Default.aspx:
    
    <%@ Page Language="VB" AutoEventWireup="false" %>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title>Untitled Page</title>
    </head>
    <body>
        <form id="form1" runat="server">
        <div>
        <%
            Dim i As Integer
            For i = Asc("A") To Asc("Z")
                Response.Write("<a href='Default.aspx?c=" & Chr(i) & "'>" & Chr(i) & "</a>&nbsp;&nbsp;")
            Next
            %>
        </div><br />
        <div>
        <%
            Dim c As String
            
            c = Request.QueryString("c")
            
            If c <> "" Then
                Dim objConn, objRS As Object
                Dim sql As String
                
                c = Left(c, 1)
                sql = "SELECT ID, pName FROM prospects WHERE pName LIKE '" & c & "%'"
            
                objConn = CreateObject("ADODB.Connection")
                objConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("db.mdb") & ";"
                objConn.Open()
                objRS = CreateObject("ADODB.Recordset")
                objRS.Open(sql, objConn, 2, 3)
                
                If objRS.eof Then Response.Write("No matches found")
                
                Do While Not objRS.eof
                    Response.Write("<a href='details.aspx?id=" & objRS("ID").value & "' target='_blank'>" & objRS("pName").value & "</a><br>")
                    objRS.moveNext()
                Loop
            
                objRS.close()
                objConn.close()
                objRS = Nothing
                objConn = Nothing
            End If
         %>
        </div>
        </form>
    </body>
    </html>
    
    Code (markup):
    I've used db.mdb (access 2002-03 database) for the example. It contains a table named prospects with and ID autonumber field and pName as a string.
    All that's left to do is create the page details.aspx , which gets the id from the querystring and shows a form to edit any other data.
     
    camjohnson95, May 2, 2009 IP
  3. camjohnson95

    camjohnson95 Active Member

    Messages:
    737
    Likes Received:
    17
    Best Answers:
    0
    Trophy Points:
    60
    #3
    Oh and to sort the results alphabetically just change the query to:
    
    sql = "SELECT ID, pName FROM prospects WHERE pName LIKE '" & c & "%' ORDER BY pName ASC"
    
    Code (markup):
     
    camjohnson95, May 2, 2009 IP