469,581 Members | 1,960 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,581 developers. It's quick & easy.

Better way to do this?

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_Re gistration_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}&categ ory_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_Selectio ns", "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("@R owCount").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_Categor y_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
Nov 18 '05 #1
1 1034
Hi,
It's always better to developed with layer application approach. move
your access DB code from page into separate DAL assembly.

Natty Gur[MVP]

blog : http://weblogs.asp.net/ngur
Mobile: +972-(0)52-8888377
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by ForHimself Every Man | last post: by
10 posts views Thread by michael newport | last post: by
24 posts views Thread by Faith Dorell | last post: by
39 posts views Thread by bazad | last post: by
33 posts views Thread by Protoman | last post: by
22 posts views Thread by JoeC | last post: by
21 posts views Thread by gavino | last post: by
3 posts views Thread by Ryan Liu | last post: by
43 posts views Thread by Pawel_Iks | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.