S
Steve
Hi All,
I'm developing a set of custom controls for a trouble ticket website.
I have a class that handles accessing the database for calls such as
add a ticket, view a ticket given an id and view a list of tickets.
I have subsequent custom controls that take care of rendering the
relevant data on the page. Such as ViewTicket ViewTicketList, etc.
Everything is going just fine, except for one thing, herein lies my
problem.
My ViewTicketList control displays a datagrid where one of the columns
is a ButtonColumn that is a link button whose datatextfield is the
ticketId. The user should click on this button to view the details of
the ticket, that are then displayed using my ViewTicket control.
How do I get to the ticketId?
Thanks in advance. Hopefully, I've provided all the information you
may need.
Code for ViewTicketList is as follows:
Imports System.ComponentModel
Imports System.Web.UI
<ToolboxData("<{0}:ViewTicketList
runat=server></{0}:ViewTicketList>")> _
Public Class ViewTicketList
Inherits Control
Implements INamingContainer
Dim _statusMessage As String
Dim _ticketID As Integer
Private WithEvents ticketGrid As WebControls.DataGrid
Private ticket As New ticket
Private ticketlist As DataModels.TicketList = ticket.TicketList
Public Event DisplayListSuccess As EventHandler
Public Event DisplayListFailure As EventHandler
Public Event TicketSelected As EventHandler
#Region "Properties"
<Bindable(False), Browsable(False)> _
ReadOnly Property StatusMessage() As String
Get
Return _statusMessage
End Get
End Property
<Bindable(False), Browsable(False)> _
ReadOnly Property TicketID() As Integer
Get
Return _ticketID
End Get
End Property
#End Region
Protected Overrides Sub CreateChildControls()
ticketGrid = New WebControls.DataGrid
ticketGrid.AutoGenerateColumns = False
Dim ticketId As New WebControls.ButtonColumn
ticketId.HeaderText = "Ticket"
ticketId.DataTextField = "ticketId"
ticketId.ButtonType = WebControls.ButtonColumnType.LinkButton
ticketGrid.Columns.Add(ticketId)
Dim summary As New WebControls.BoundColumn
summary.HeaderText = "Summary"
summary.DataField = "summary"
summary.ItemStyle.Width = New WebControls.Unit(400)
ticketGrid.Columns.Add(summary)
Dim status As New WebControls.BoundColumn
status.HeaderText = "Status"
status.DataField = "status"
status.ItemStyle.Width = New WebControls.Unit(100)
status.ItemStyle.HorizontalAlign =
WebControls.HorizontalAlign.Center
ticketGrid.Columns.Add(status)
Dim dateOpened As New WebControls.BoundColumn
dateOpened.HeaderText = "Date Opened"
dateOpened.DataField = "dateOpen"
ticketGrid.Columns.Add(dateOpened)
Me.Controls.Add(ticketGrid)
End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If ticket.ViewList() Then
ticketGrid.DataSource = ticketlist
ticketGrid.DataKeyField = "ticketId"
ticketGrid.DataBind()
_statusMessage = ticket.StatusMessage
RaiseEvent DisplayListSuccess(Me, EventArgs.Empty)
Else
_statusMessage = ticket.StatusMessage
RaiseEvent DisplayListFailure(Me, EventArgs.Empty)
End If
End Sub
Private Sub ticketGrid_ItemCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
ticketGrid.ItemCommand
_statusMessage = "Ticket " & _ticketID & " selected."
RaiseEvent TicketSelected(Me, EventArgs.Empty)
End Sub
End Class
In my aspx page I have:
Private Sub ViewTicketList1_TicketSelected(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ViewTicketList1.TicketSelected
ViewTicket1.TicketId = ViewTicketList1.TicketID
ViewTicket1.Visible = True
End Sub
The Ticket.ViewList function is:
Public Function ViewList() As Boolean
Dim conn As New
SqlConnection(ConfigurationSettings.AppSettings("DBConnectionString"))
Dim sqlGetTickets As New SqlCommand("supportTickets", conn)
sqlGetTickets.CommandType = CommandType.StoredProcedure
_DataAdapter.SelectCommand = sqlGetTickets
_DataAdapter.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() { _
New System.Data.Common.DataTableMapping("Table",
"TicketList", _
New System.Data.Common.DataColumnMapping() { _
New System.Data.Common.DataColumnMapping("ticketId",
"ticketId"), _
New System.Data.Common.DataColumnMapping("productId",
"productId"), _
New System.Data.Common.DataColumnMapping("statusId",
"statusId"), _
New System.Data.Common.DataColumnMapping("summary",
"summary"), _
New System.Data.Common.DataColumnMapping("description",
"description"), _
New System.Data.Common.DataColumnMapping("dateOpen",
"dateOpen"), _
New System.Data.Common.DataColumnMapping("status",
"status"), _
New System.Data.Common.DataColumnMapping("productName",
"productName"), _
New System.Data.Common.DataColumnMapping("version",
"version"), _
New System.Data.Common.DataColumnMapping("contactId",
"contactId"), _
New System.Data.Common.DataColumnMapping("companyId",
"companyId"), _
New System.Data.Common.DataColumnMapping("firstName",
"firstName"), _
New System.Data.Common.DataColumnMapping("lastName",
"lastName"), _
New System.Data.Common.DataColumnMapping("email",
"email"), _
New System.Data.Common.DataColumnMapping("username",
"username"), _
New System.Data.Common.DataColumnMapping("companyName",
"companyName")})})
Try
conn.Open()
_DataAdapter.Fill(_Ticketlist)
_StatusMessage = "Successfully retrieved tickets."
Return True
Catch ex As Exception
_StatusMessage = "Failed to retrieve tickets." &
ex.Message
Return False
Finally
conn.Close()
End Try
End Function
I'm developing a set of custom controls for a trouble ticket website.
I have a class that handles accessing the database for calls such as
add a ticket, view a ticket given an id and view a list of tickets.
I have subsequent custom controls that take care of rendering the
relevant data on the page. Such as ViewTicket ViewTicketList, etc.
Everything is going just fine, except for one thing, herein lies my
problem.
My ViewTicketList control displays a datagrid where one of the columns
is a ButtonColumn that is a link button whose datatextfield is the
ticketId. The user should click on this button to view the details of
the ticket, that are then displayed using my ViewTicket control.
How do I get to the ticketId?
Thanks in advance. Hopefully, I've provided all the information you
may need.
Code for ViewTicketList is as follows:
Imports System.ComponentModel
Imports System.Web.UI
<ToolboxData("<{0}:ViewTicketList
runat=server></{0}:ViewTicketList>")> _
Public Class ViewTicketList
Inherits Control
Implements INamingContainer
Dim _statusMessage As String
Dim _ticketID As Integer
Private WithEvents ticketGrid As WebControls.DataGrid
Private ticket As New ticket
Private ticketlist As DataModels.TicketList = ticket.TicketList
Public Event DisplayListSuccess As EventHandler
Public Event DisplayListFailure As EventHandler
Public Event TicketSelected As EventHandler
#Region "Properties"
<Bindable(False), Browsable(False)> _
ReadOnly Property StatusMessage() As String
Get
Return _statusMessage
End Get
End Property
<Bindable(False), Browsable(False)> _
ReadOnly Property TicketID() As Integer
Get
Return _ticketID
End Get
End Property
#End Region
Protected Overrides Sub CreateChildControls()
ticketGrid = New WebControls.DataGrid
ticketGrid.AutoGenerateColumns = False
Dim ticketId As New WebControls.ButtonColumn
ticketId.HeaderText = "Ticket"
ticketId.DataTextField = "ticketId"
ticketId.ButtonType = WebControls.ButtonColumnType.LinkButton
ticketGrid.Columns.Add(ticketId)
Dim summary As New WebControls.BoundColumn
summary.HeaderText = "Summary"
summary.DataField = "summary"
summary.ItemStyle.Width = New WebControls.Unit(400)
ticketGrid.Columns.Add(summary)
Dim status As New WebControls.BoundColumn
status.HeaderText = "Status"
status.DataField = "status"
status.ItemStyle.Width = New WebControls.Unit(100)
status.ItemStyle.HorizontalAlign =
WebControls.HorizontalAlign.Center
ticketGrid.Columns.Add(status)
Dim dateOpened As New WebControls.BoundColumn
dateOpened.HeaderText = "Date Opened"
dateOpened.DataField = "dateOpen"
ticketGrid.Columns.Add(dateOpened)
Me.Controls.Add(ticketGrid)
End Sub
Protected Overrides Sub OnPreRender(ByVal e As System.EventArgs)
If ticket.ViewList() Then
ticketGrid.DataSource = ticketlist
ticketGrid.DataKeyField = "ticketId"
ticketGrid.DataBind()
_statusMessage = ticket.StatusMessage
RaiseEvent DisplayListSuccess(Me, EventArgs.Empty)
Else
_statusMessage = ticket.StatusMessage
RaiseEvent DisplayListFailure(Me, EventArgs.Empty)
End If
End Sub
Private Sub ticketGrid_ItemCommand(ByVal source As Object, ByVal e
As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
ticketGrid.ItemCommand
_statusMessage = "Ticket " & _ticketID & " selected."
RaiseEvent TicketSelected(Me, EventArgs.Empty)
End Sub
End Class
In my aspx page I have:
Private Sub ViewTicketList1_TicketSelected(ByVal sender As Object,
ByVal e As System.EventArgs) Handles ViewTicketList1.TicketSelected
ViewTicket1.TicketId = ViewTicketList1.TicketID
ViewTicket1.Visible = True
End Sub
The Ticket.ViewList function is:
Public Function ViewList() As Boolean
Dim conn As New
SqlConnection(ConfigurationSettings.AppSettings("DBConnectionString"))
Dim sqlGetTickets As New SqlCommand("supportTickets", conn)
sqlGetTickets.CommandType = CommandType.StoredProcedure
_DataAdapter.SelectCommand = sqlGetTickets
_DataAdapter.TableMappings.AddRange(New
System.Data.Common.DataTableMapping() { _
New System.Data.Common.DataTableMapping("Table",
"TicketList", _
New System.Data.Common.DataColumnMapping() { _
New System.Data.Common.DataColumnMapping("ticketId",
"ticketId"), _
New System.Data.Common.DataColumnMapping("productId",
"productId"), _
New System.Data.Common.DataColumnMapping("statusId",
"statusId"), _
New System.Data.Common.DataColumnMapping("summary",
"summary"), _
New System.Data.Common.DataColumnMapping("description",
"description"), _
New System.Data.Common.DataColumnMapping("dateOpen",
"dateOpen"), _
New System.Data.Common.DataColumnMapping("status",
"status"), _
New System.Data.Common.DataColumnMapping("productName",
"productName"), _
New System.Data.Common.DataColumnMapping("version",
"version"), _
New System.Data.Common.DataColumnMapping("contactId",
"contactId"), _
New System.Data.Common.DataColumnMapping("companyId",
"companyId"), _
New System.Data.Common.DataColumnMapping("firstName",
"firstName"), _
New System.Data.Common.DataColumnMapping("lastName",
"lastName"), _
New System.Data.Common.DataColumnMapping("email",
"email"), _
New System.Data.Common.DataColumnMapping("username",
"username"), _
New System.Data.Common.DataColumnMapping("companyName",
"companyName")})})
Try
conn.Open()
_DataAdapter.Fill(_Ticketlist)
_StatusMessage = "Successfully retrieved tickets."
Return True
Catch ex As Exception
_StatusMessage = "Failed to retrieve tickets." &
ex.Message
Return False
Finally
conn.Close()
End Try
End Function