Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP .Net Datagrid Control > Can't reference a datagrid cell

Reply
Thread Tools

Can't reference a datagrid cell

 
 
Steve
Guest
Posts: n/a
 
      04-01-2004
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("D BConnectionString"))
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Reference Datagrid cell contents =?Utf-8?B?TXJNaWtl?= ASP .Net 3 03-11-2010 09:49 PM
datagrid itemIndex cell reference janetb ASP .Net Web Controls 0 05-10-2006 07:24 PM
How to set cell background based on cell value when datagrid is displayed RJ ASP .Net Datagrid Control 1 02-17-2005 09:37 PM
RadioButtonList In A DataGrid Cell - Can I find the selected button without editing the cell? Empire City ASP .Net Datagrid Control 3 04-30-2004 12:19 AM
multilink cell phones multilinking shotgun 2 cell phones Calvin Cisco 1 11-07-2003 02:20 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57