ASP file
----------------
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="viewreport.aspx.vb" Inherits="viewreport" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<%@ Import Namespace="System.Data" %>
<!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 id="PageHead" runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Human Resourses </title>
<link href="Default.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.invertedshiftdown2{
padding: 0;
width: 78%;
border-top: 5px solid #000099; /*Highlight blue color theme*/
background: transparent;
voice-family: "\"}\"";
voice-family: inherit;
}
.invertedshiftdown2 ul{
margin:0;
margin-left: 40px; /*margin between first menu item and left browser edge*/
padding: 0;
list-style: none;
}
.invertedshiftdown2 li{
display: inline;
margin: 0 2px 0 0;
padding: 0;
text-transform:uppercase;
}
.invertedshiftdown2 a{
float: left;
display: block;
font: bold 12px Arial;
color: black;
text-decoration: none;
margin: 0 1px 0 0; /*Margin between each menu item*/
padding: 5px 10px 5px 10px; /*Padding within each menu item*/
background-color: lightblue; /*Default menu color*/
border-bottom: 8px solid white;
}
.invertedshiftdown2 a:hover{
background-color: #000099; /*Highlight red color theme*/
padding-top: 10px; /*Set padding-top value to default's padding-top + padding-bottom */
padding-bottom: 0; /*Set padding-bottom value to 0 */
border-bottom-color: #000099; /*Highlight red color theme*/
color: white;
}
.invertedshiftdown2 .current a{ /** currently selected menu item **/
background-color: #D10000; /*Highlight red color theme*/
padding-top: 10px; /*Set padding-top value to default's padding-top + padding-bottom */
padding-bottom: 0; /*Set padding-bottom value to 0 */
border-bottom-color: #D10000; /*Highlight red color theme*/
color: white;
}
#myform{ /*CSS for sample search box. Remove if desired */
float: right;
margin: 0;
margin-top: 2px;
padding: 0;
}
#myform .textinput{
width: 190px;
border: 1px solid gray;
}
#myform .submit{
font: normal 12px Verdana;
height: 22px;
border: 1px solid #000099;
background-color: black;
color: white;
}
</style>
</head>
<body style="background-color: white">
<form id="FormMain" runat="server">
<table width="770px" border="0" cellspacing="0" cellpadding="0">
<tr class="StandardPageHeader">
<td width="1" bgcolor="#FFFFFF" align="left">
<a href="http://www.tamu-commerce.edu"><img src="BlockLogo.jpg" alt="Passionate About Learning? You Belong Here." border="0" style="height: 111px"/></a>
</td>
<td align="left">
<img src="StudentsAtComputer.jpg" style="width: 555px; height: 114px" /> </td>
</tr>
</table>
<div class="invertedshiftdown2" style="height: 36px; text-align: center;">
<ul>
<li style="text-align: center"><a href="default.aspx" title="Home">Home</a></li>
<li style="text-align: center"><a href="addCourse.aspx" title="New">Add Course</a></li>
<li style="text-align: center"><a href="viewreport.aspx" title="Tools">Reports</a></li>
<li style="text-align: center"><a href="help.aspx" title="Help">Help</a></li>
</ul>
</div>
<table width="770px" border="0" cellspacing="0" cellpadding="0">
<tr>
<td colspan="2" style="height: 15px; text-align: center;">
<asp:PlaceHolder ID="PageBody" runat="server" />
<br />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:TCPRODConnectionString3 %>"
SelectCommand="SELECT [CNAME] FROM [CHRTR]"></asp:SqlDataSource>
<br />
<asp:Label ID="show" runat="server" Width="193px" ForeColor="Red"></asp:Label><br />
<br />
<asp:DropDownList ID="course" runat="server" DataSourceID="SqlDataSource1" DataTextField="CNAME"
DataValueField="CNAME" AutoPostBack="True">
</asp:DropDownList>
<asp:TextBox ID="cn" runat="server" Visible="False"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="Go" /><br />
</td>
</tr>
</table>
</form>
<asp:Label cssclass="StandardPageHeader" runat="server" ID="Footer" Width="768px" BackColor="#0000C0">.</asp:label>
</body>
</html>
VB file
-------------
Partial Class viewreport
Inherits System.Web.UI.Page
Dim ConnPortal As ADODB.Connection
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
cn.Text = ""
Dim r As TableRow ' create a new row
Dim c As TableCell ' create a new cell
Dim t As Table = New Table ' make a new table
Dim l As Label ' lable that shows the user thatrs loged in
Dim rs As ADODB.Recordset ' recorde set for the connection
Dim sqlstmt As String
Dim CNAME As String
Dim FNAME As String
Dim LNAME As String
Dim EMAIL As String
Dim PHONE As String
Dim ct As Integer = 0
Call localDBConnectionOpen()
' sqlstmt = "SELECT * FROM HRD WHERE ('" & cn.Text & "')= CNAME"
sqlstmt = "SELECT c.* FROM CHRTR c INNER JOIN Registrations r ON r.CourseID=c.ID "
rs = DBRecordSetNewFast(ConnPortal, sqlstmt)
l = New Label
l.Text = " <br />"
PageBody.Controls.Add(l)
l = New Label
l.Text = "Logged on user: " & Request.ServerVariables("AUTH_USER")
PageBody.Controls.Add(l)
t = New Table
t.Width = Unit.Percentage(100)
' creates the table for the diplay
r = New TableRow
r.VerticalAlign = VerticalAlign.Bottom
r.CssClass = "StandardRowHeader"
c = New TableHeaderCell
c.Text = "Course Name"
r.Controls.Add(c)
c = New TableCell
c.Text = "First name"
r.Controls.Add(c)
c = New TableHeaderCell
c.Text = "Last Name"
r.Controls.Add(c)
c = New TableHeaderCell
c.Text = "Email"
r.Controls.Add(c)
c = New TableHeaderCell
c.Text = "Phone"
r.Controls.Add(c)
t.Controls.Add(r)
While Not rs.EOF
CNAME = DBGetField(rs, "CNAME")
FNAME = DBGetField(rs, "FNAME")
LNAME = DBGetField(rs, "LNAME")
EMAIL = DBGetField(rs, "EMAIL")
PHONE = DBGetField(rs, "PHONE")
r = New TableRow
ct += 1
If ct Mod 2 = 0 Then
r.CssClass = "StandardRowEven"
Else
r.CssClass = "StandardRowOdd"
End If
'call to the varabkes that hold the data from the database
Call CellAdd(r, CNAME.ToString)
Call CellAdd(r, FNAME.ToString)
Call CellAdd(r, LNAME.ToString)
Call CellAdd(r, EMAIL.ToString)
Call CellAdd(r, PHONE.ToString)
t.Controls.Add(r)
rs.MoveNext()
End While
PageBody.Controls.Add(t)
rs = DBRecordSetDestroy(rs)
Call localDBConnectionClose()
End Sub
Private Sub CellAdd(ByRef r As TableRow, ByVal t As String)
Dim c = New TableCell
c.text = t
r.Controls.Add(c)
c = Nothing
End Sub
Private Sub localDBConnectionOpen()
ConnPortal = DBConnectionOpenSQLServer(ConnPortal, "TCPROD", "SQL01", "HRProd", "Ev3rgr8en!")
End Sub
Private Sub localDBConnectionClose()
ConnPortal = DBConnectionClose(ConnPortal)
End Sub
' bind the drop down to the text boxthat is unknown
Protected Sub course_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles course.SelectedIndexChanged
cn.Text = course.SelectedItem.Value.ToString
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
End Sub
End Class
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
ASKER
aspx:
===========================================
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString1 %>"
SelectCommand="SELECT [CustomerID], [CompanyName] FROM [Customers]"></asp:SqlDataSource>
<asp:DropDownList ID="DropDownList1" runat="server" AppendDataBoundItems="true" AutoPostBack="True"
DataSourceID="SqlDataSource1" DataTextField="CompanyName" DataValueField="CustomerID">
<asp:ListItem Text="Please Select" Value=""></asp:ListItem>
</asp:DropDownList><br />
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="true">
</asp:GridView>
codebehind:
===========================================
'(be sure the codebehind Imports system.data and system.data.sqlclient)
Private Function ShowOrdersByCustomerID(ByVal CustomerID As String) As DataTable
Try
Using MyConn As New SqlConnection(ConfigurationManager.ConnectionStrings("NorthwindConnectionString1").ConnectionString)
MyConn.Open()
Dim MyCmd As New SqlCommand("SELECT * FROM Orders WHERE CustomerID = @CustomerID", MyConn)
MyCmd.Parameters.Add(New SqlParameter("@CustomerID", CustomerID))
MyCmd.CommandType = CommandType.Text
Dim MyAdapter As New SqlDataAdapter
Dim MyDataset As New DataSet
MyAdapter.SelectCommand = MyCmd
MyAdapter.Fill(MyDataset)
Return MyDataset.Tables(0)
End Using
Catch ex As Exception
Response.Write("Error in ShowOrdersByCustomerID: " & ex.Message.ToString())
Dim dt As New DataTable
Return dt
End Try
End Function
Private Sub DropDownList1_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles DropDownList1.SelectedIndexChanged
Try
Me.GridView1.DataSource = Me.ShowOrdersByCustomerID(Me.DropDownList1.SelectedValue)
Me.GridView1.DataBind()
Catch ex As Exception
Response.Write("Error in DropDownList1_SelectedIndexChanged: " & ex.Message.ToString())
End Try
End Sub
The successor to Active Server Pages, ASP.NET websites utilize the .NET framework to produce dynamic, data and content-driven web applications and services. ASP.NET code can be written using any .NET supported language. As of 2009, ASP.NET can also apply the Model-View-Controller (MVC) pattern to web applications
TRUSTED BY