Better way to do this?

C

Chad A. Beckner

Hey all,

I am developing a workshop registration system, and am new to ASP .NET.
On my first page, I want to list the "categories" available along with the
number of "workshops" related to that category. I have it working, but want
to know if there is a better way to do this. I have listed the code below,
any help would be VERY much appreciated.

----- CODE FOR MAIN PAGE -----

<%@ Page Language="vb" AutoEventWireup="false"
Codebehind="workshop_registration_system.aspx.vb"
Inherits="Workshop_Registration_System.Workshop_Registration_System"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Workshop Registration System | View Categories</title>
<meta content="Microsoft Visual Studio .NET 7.1" name="GENERATOR">
<meta content="Visual Basic .NET 7.1" name="CODE_LANGUAGE">
<meta content="JavaScript" name="vs_defaultClientScript">
<meta content="http://schemas.microsoft.com/intellisense/ie5"
name="vs_targetSchema">
</HEAD>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<p align="center"><font face="Arial" color="#800000" size="4"><b>Welcome
to the IUSD
Workshop Registration System, v1.00</b></font></p>
<p align="center"><asp:datalist id="dlWorkshop_Category_Selections"
runat="server" BorderColor="#CC9966" BorderStyle="None"
BorderWidth="1px" BackColor="White" CellPadding="2" GridLines="Both"
Width="500px" RepeatColumns="2">
<SelectedItemStyle Font-Bold="True" Wrap="False" ForeColor="#663399"
BackColor="#FFCC66"></SelectedItemStyle>
<HeaderTemplate>
Please select a workshop category from below
</HeaderTemplate>
<ItemStyle Font-Size="10pt" Font-Names="Arial" Wrap="False"
ForeColor="#330099" BackColor="White"></ItemStyle>
<ItemTemplate>
<A href='<%# Databinder.Eval(Container.DataItem, "ID",
"view_category.aspx?workshop_category_id={0}&category_name=" ) %><%#
Databinder.Eval(Container.DataItem, "Short_Name") %> '>
<asp:Label id="lblWorkshop_Category_Title" runat="server" Text='<%#
Databinder.Eval(Container.DataItem, "Short_Name") %>'>
</asp:Label>
(<asp:Label id="lblWorkshop_Category_Workshops_Count" runat="server">
</asp:Label> workshops)</A>
</ItemTemplate>
<FooterStyle ForeColor="#330099" BackColor="#FFFFCC"></FooterStyle>
<HeaderStyle Font-Bold="True" Wrap="False" ForeColor="#FFFFCC"
BackColor="#990000"></HeaderStyle>
</asp:datalist></p>
</form>
</body>
</HTML>

----- CODEBEHIND FOR MAIN PAGE -----

Imports System.Data.SqlClient

Public Class Workshop_Registration_System
Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "

'This call is required by the Web Form Designer.
<System.Diagnostics.DebuggerStepThrough()> Private Sub
InitializeComponent()

End Sub
Protected WithEvents dlWorkshop_Category_Selections As
System.Web.UI.WebControls.DataList
Protected WithEvents lblWorkshop_Category_Title As
System.Web.UI.WebControls.Label
Protected WithEvents lblWorkshop_Category_Workshops_Count As
System.Web.UI.WebControls.Label

'NOTE: The following placeholder declaration is required by the Web Form
Designer.
'Do not delete or move it.
Private designerPlaceholderDeclaration As System.Object

Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Init
'CODEGEN: This method call is required by the Web Form Designer
'Do not modify it using the code editor.
InitializeComponent()
End Sub

#End Region

Dim dsWorkshop_Categories As DataSet

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
If Not Page.IsPostBack Then
Dim daWorkshop_Categories As New SqlDataAdapter


daWorkshop_Categories =
DataHandler.GetDataAdapter("spGetCategory_Selections", "Training_System")
daWorkshop_Categories.SelectCommand.CommandType =
CommandType.StoredProcedure

' Create and add an output parameter to Parameters collection, then
' set the direction for the parameter. This parameter returns the Rows
returned.
daWorkshop_Categories.SelectCommand.Parameters.Add(New
SqlParameter("@RowCount", SqlDbType.Int, 4))
daWorkshop_Categories.SelectCommand.Parameters("@RowCount").Direction =
ParameterDirection.Output

dsWorkshop_Categories = New DataSet
daWorkshop_Categories.Fill(dsWorkshop_Categories,
"tblWorkshop_Categories")
dsWorkshop_Categories.Tables(0).TableName = "Workshop_Categories"
dsWorkshop_Categories.Tables(1).TableName = "Workshop_Selections"

With dlWorkshop_Category_Selections
.DataSource = dsWorkshop_Categories
.DataBind()
End With

daWorkshop_Categories.Dispose()
DataHandler.Close_DBConn(DataHandler.cnnDBConn)
End If
End Sub

Private Sub dlWorkshop_Category_Selections_ItemDataBound(ByVal sender As
Object, ByVal e As System.Web.UI.WebControls.DataListItemEventArgs) Handles
dlWorkshop_Category_Selections.ItemDataBound
If e.Item.ItemType = ListItemType.Item Or e.Item.ItemType =
ListItemType.AlternatingItem Then
Dim dvWorkshop_Selections As DataView =
dsWorkshop_Categories.Tables("Workshop_Selections").DefaultView
dvWorkshop_Selections.RowFilter = "Workshop_Category_ID = '" &
Convert.ToString(CType(e.Item.DataItem, DataRowView).Row.Item("ID")) & "'"

Dim lblToChange As Label
lblToChange =
DirectCast(e.Item.FindControl("lblWorkshop_Category_Workshops_Count"),
Label)
lblToChange.Text = dvWorkshop_Selections.Count.ToString
End If
End Sub
End Class


----- SQL Stored Procedure -----

ALTER PROCEDURE dbo.spGetCategory_Selections
(
@RowCount int output
)
AS
SELECT ID, Short_Name, Long_Name FROM tblWorkshop_Category_Selections WHERE
(Active = 1) AND (Status_ID = 1) ORDER BY Short_Name;
SELECT @RowCount = @@ROWCOUNT
SELECT * FROM tblWorkshop_Selections;
RETURN
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top