Hi!
I have created a custom server control which implements your data grid.
Everything works fine except that when I click the “delete” button it does not fire the “ItemCommand” event. It does go to the server however.
I have attached my code here so you can take a look.
Thank you in advance!
Imports System
Imports System.Web.UI.WebControls
Imports System.Web.UI
Imports Telerik.WebControls
Imports System.ComponentModel
<DefaultProperty(""), ToolboxData("<{0}:npaGeneralDataGrid runat=server></{0}:npaGeneralDataGrid>")> _
Public Class npaGeneralDataGrid
Inherits Global.Telerik.WebControls.RadGrid
Private _ShowColumnEmployeeNumber As Boolean = False
Private _ShowColumnDeleteNPA As Boolean = False
Private _iconDeleteNPA As String
Private _GridType As GridTypeEnum
'Private oUserProfile As NPABusinessServices.UserProfile
Private _dataGridOwner As String
#Region "Custom Properties"
Public Property GridType() As GridTypeEnum
Get
Return _GridType
End Get
Set(ByVal value As GridTypeEnum)
_GridType = value
End Set
End Property
Public Property ShowColumnEmployeeNumber() As Boolean
Get
Return _ShowColumnEmployeeNumber
End Get
Set(ByVal value As Boolean)
_ShowColumnEmployeeNumber = value
End Set
End Property
Public Property ShowColumnDeleteNPA() As Boolean
Get
Return _ShowColumnDeleteNPA
End Get
Set(ByVal value As Boolean)
_ShowColumnDeleteNPA = value
End Set
End Property
Public Property iconDeleteNPA() As String
Get
Return _iconDeleteNPA
End Get
Set(ByVal value As String)
_iconDeleteNPA = value
End Set
End Property
#End Region
#Region "Grid Type Enumeratior"
Public Enum GridTypeEnum As Integer
Drafts = 0
End Enum
#End Region
Public Sub New()
MyBase.New()
MyBase.AutoGenerateColumns = False
End Sub
Private Sub npaGeneralDataGrid_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim oCol As GridColumn
oCol = New EmployeeNumber
oCol.HeaderText = "Emp No."
oCol.SortExpression = "LastName"
oCol.HeaderStyle.Width = Unit.Pixel(60)
oCol.HeaderStyle.HorizontalAlign = WebControls.HorizontalAlign.Left
oCol.ItemStyle.HorizontalAlign = WebControls.HorizontalAlign.Left
oCol.Visible = Me.ShowColumnEmployeeNumber
MyBase.MasterTableView.Columns.Add(oCol)
oCol = New DeleteNPA(_iconDeleteNPA)
MyBase.MasterTableView.Columns.Add(oCol)
oCol.HeaderText = ""
oCol.HeaderStyle.HorizontalAlign = WebControls.HorizontalAlign.Left
oCol.ItemStyle.HorizontalAlign = WebControls.HorizontalAlign.Left
oCol.Visible = Me.ShowColumnDeleteNPA
End Sub
Private Sub npaGeneralDataGrid_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
''data gets binded here - works beautifully
End Sub
Private Sub npaGeneralDataGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles Me.ItemCommand
''this is never fired
Select Case e.CommandName.ToUpper()
Case "DELETE"
Case "DESELECT"
Case "PAGE"
End Select
End Sub
End Class
''class containing the column definition
Imports System
Imports System.Data
Imports System.Configuration
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls
Imports Telerik.WebControls
Public Class EmployeeNumber
Inherits GridTemplateColumn
Private Class ActualClass
Implements ITemplate
Public Column As EmployeeNumber = Nothing
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim oLabel As New Label
oLabel.ID = "lblEmployeeNumber"
container.Controls.Add(oLabel)
AddHandler oLabel.DataBinding, AddressOf BindObject
End Sub
Public Sub BindObject(ByVal sender As Object, ByVal e As EventArgs)
'Create a new instance of a Label.
Dim oLabel As Label = CType(sender, Label)
Dim container As GridDataItem = CType(oLabel.NamingContainer, GridDataItem)
'Bind the employee name to the label text
If Not IsDBNull(container.DataItem("EmployeeNumber")) Then
oLabel.Text = container.DataItem("EmployeeNumber")
End If
End Sub
End Class
Public Sub New()
Dim template As New ActualClass
template.Column = Me
Me.ItemTemplate = template
End Sub
End Class
Public Class LastUpdatedDate
Inherits GridTemplateColumn
Private Class ActualClass
Implements ITemplate
Public Column As LastUpdatedDate = Nothing
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim oLabel As New Label
oLabel.ID = "lblLastUpdatedDate"
container.Controls.Add(oLabel)
AddHandler oLabel.DataBinding, AddressOf BindObject
End Sub
Public Sub BindObject(ByVal sender As Object, ByVal e As EventArgs)
'Create a new instance of a Label.
Dim oLabel As Label = CType(sender, Label)
Dim container As GridDataItem = CType(oLabel.NamingContainer, GridDataItem)
'Bind the employee name to the label text
oLabel.Text = container.DataItem("LastUpdatedDate")
End Sub
End Class
Public Sub New()
Dim template As New ActualClass
template.Column = Me
Me.ItemTemplate = template
End Sub
End Class
Public Class DeleteNPA
Inherits GridTemplateColumn
Private Shared _IconPath As String
Private Class ActualClass
Implements ITemplate
Public Column As DeleteNPA = Nothing
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
Dim oImageButton As New ImageButton
oImageButton.ID = "imgDeleteNPA"
oImageButton.ImageUrl = _IconPath
'oImageButton.CommandName = "delete"
container.Controls.Add(oImageButton)
AddHandler oImageButton.DataBinding, AddressOf BindObject
End Sub
Public Sub BindObject(ByVal sender As Object, ByVal e As EventArgs)
''Get the label's instance
Dim oImageButton As ImageButton = CType(sender, ImageButton)
Dim container As GridDataItem = CType(oImageButton.NamingContainer, GridDataItem)
''Bind the object's CommandArgument to the NPAID
oImageButton.CommandArgument = container.DataItem("NPAID")
oImageButton.CommandName = "delete"
End Sub
End Class
Public Sub New(ByVal iconPath As String)
Dim template As New ActualClass
template.Column = Me
Me.ItemTemplate = template
Me.AllowFiltering = False
_IconPath = iconPath
End Sub
End Class