My Code is below and the Delete Button is not working?
aspx
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<asp:PlaceHolder ID="phdrGrid" runat="server" ></asp:PlaceHolder>
<asp:SqlDataSource ID="sqldsGrid" runat="server"
ConnectionString="<%$ ConnectionStrings:EFDBConnectionString %>"
SelectCommand="SELECT * FROM [sites]"
UpdateCommand="UPDATE [sites] SET [SiteName]=@SiteName WHERE [SiteId]=@SiteId"
DeleteCommand="DELETE FROM [sites] WHERE [SiteId]=@SiteId">
<UpdateParameters>
<asp:Parameter Name="@SiteId" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="@SiteId" />
</DeleteParameters>
</asp:SqlDataSource>
aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Partial Public Class _Default
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim RadGrid1 As New RadGrid()
'RadGrid1.NeedDataSource += New GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource)
'RadGrid1.ItemCommand += New GridCommandEventHandler(RadGrid1_ItemCommand)
'RadGrid1.ItemCreated += New GridItemEventHandler(RadGrid1_ItemCreated)
'RadGrid1.ID = "rgDemo"
RadGrid1.Width = Unit.Percentage(100)
RadGrid1.PageSize = 3
RadGrid1.AllowPaging = True
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
RadGrid1.AutoGenerateColumns = False
RadGrid1.GroupingEnabled = True
RadGrid1.ShowGroupPanel = True
RadGrid1.ShowStatusBar = True
RadGrid1.ClientSettings.AllowDragToGroup = True
RadGrid1.DataSourceID = "sqldsGrid"
RadGrid1.Skin = "Outlook"
RadGrid1.MasterTableView.PageSize = 15
RadGrid1.MasterTableView.DataKeyNames = New String() {"SiteId"}
RadGrid1.MasterTableView.AllowAutomaticUpdates = True
'RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace
'Dim gtc As New GridTemplateColumn()
'gtc.ItemTemplate = New ItemTemplateLabels("Description")
'gtc.HeaderText = "Description"
'gtc.EditItemTemplate = New EditItemTemplateTextBoxes("Description")
'RadGrid1.MasterTableView.Columns.Add(gtc)
'Dim gt2 As New GridTemplateColumn()
'gt2.ItemTemplate = New ItemTemplateLabels("Name")
'gt2.HeaderText = "Name"
'gt2.EditItemTemplate = New EditItemTemplateTextBoxes("Name")
'RadGrid1.MasterTableView.Columns.Add(gt2)
Dim boundColumn1 As New GridBoundColumn()
boundColumn1.DataField = "SiteId"
boundColumn1.UniqueName = "SiteId"
boundColumn1.HeaderText = "SiteId"
RadGrid1.MasterTableView.Columns.Add(boundColumn1)
Dim boundColumn2 As New GridBoundColumn()
boundColumn2.DataField = "SiteName"
boundColumn2.UniqueName = "SiteName"
boundColumn2.HeaderText = "SiteName"
RadGrid1.MasterTableView.Columns.Add(boundColumn2)
Dim gt3 As New GridTemplateColumn()
gt3.ItemTemplate = New ItemTemplateLinks("Links")
gt3.UniqueName = "EditCommandColumn"
gt3.HeaderText = "Links"
gt3.EditItemTemplate = New EditItemTemplateLinks("Links", "Update", "Update")
gt3.EditItemTemplate = New EditItemTemplateLinks("Links", "Cancel", "Cancel")
RadGrid1.MasterTableView.Columns.Add(gt3)
Dim gBtnColumn As New GridButtonColumn()
gBtnColumn.CommandName = "Delete"
gBtnColumn.Text = "Delete"
gBtnColumn.ButtonType = GridButtonColumnType.LinkButton
RadGrid1.MasterTableView.Columns.Add(gBtnColumn)
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template
phdrGrid.Controls.Add(RadGrid1)
End Sub
Private Class ItemTemplateLinks
Implements ITemplate
Protected rBtn As RadButton
Private colname As String = String.Empty
Private colValue As String = String.Empty
Public Sub New(ByVal cName As String)
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
rBtn = New RadButton()
rBtn.Text = "Edit"
rBtn.ButtonType = RadButtonType.StandardButton
'rBtn.Command += New CommandEventHandler(rBtn_Command)
rBtn.CommandName = "Edit"
Dim rnd As New Random()
rBtn.ID = "test"
container.Controls.Add(rBtn)
End Sub
Private Sub rBtn_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim a As String = TryCast(sender, RadButton).CommandName
End Sub
End Class
Private Class EditItemTemplateLinks
Implements IBindableTemplate
Private lstItemType As ListItemType
Protected rBtn As RadButton
Protected rBtn1 As RadButton
Private colname As String = String.Empty
Private btnText As String = String.Empty
Private cmdName As String = String.Empty
Private colValue As String = String.Empty
Public Sub New(ByVal cName As String, ByVal bText As String, ByVal bCmdName As String)
btnText = bText
bCmdName = cmdName
colname = cName
End Sub
Private Sub rBtn_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim a As String = TryCast(sender, RadButton).CommandName
End Sub
Public Function ExtractValues(ByVal container As System.Web.UI.Control) As System.Collections.Specialized.IOrderedDictionary Implements System.Web.UI.IBindableTemplate.ExtractValues
Dim od As New OrderedDictionary()
Return od
End Function
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
rBtn = New RadButton()
rBtn.Text = "Update"
rBtn.ButtonType = RadButtonType.StandardButton
rBtn.CommandName = "Update"
'rBtn.Command += New CommandEventHandler(rBtn_Command)
Dim rnd As New Random()
rBtn.ID = "ssss"
container.Controls.Add(rBtn)
rBtn1 = New RadButton()
rBtn1.Text = "Cancel"
rBtn1.ButtonType = RadButtonType.StandardButton
rBtn1.CommandName = "Cancel"
Dim rnd1 As New Random()
container.Controls.Add(rBtn1)
End Sub
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
When i click the Delete Button I am getting the Following error
Server Error in '/' Application.
Exception Details: System.InvalidCastException: Unable to cast object of type 'ItemTemplateLinks' to type 'System.Web.UI.IBindableTemplate'.
Source Error:
Stack Trace:
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618
aspx
<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
</telerik:RadScriptManager>
<asp:PlaceHolder ID="phdrGrid" runat="server" ></asp:PlaceHolder>
<asp:SqlDataSource ID="sqldsGrid" runat="server"
ConnectionString="<%$ ConnectionStrings:EFDBConnectionString %>"
SelectCommand="SELECT * FROM [sites]"
UpdateCommand="UPDATE [sites] SET [SiteName]=@SiteName WHERE [SiteId]=@SiteId"
DeleteCommand="DELETE FROM [sites] WHERE [SiteId]=@SiteId">
<UpdateParameters>
<asp:Parameter Name="@SiteId" />
</UpdateParameters>
<DeleteParameters>
<asp:Parameter Name="@SiteId" />
</DeleteParameters>
</asp:SqlDataSource>
aspx.vb
Imports System.Data
Imports System.Data.SqlClient
Imports Telerik.Web.UI
Partial Public Class _Default
Inherits System.Web.UI.Page
Private Sub Page_Init(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Init
Dim RadGrid1 As New RadGrid()
'RadGrid1.NeedDataSource += New GridNeedDataSourceEventHandler(RadGrid1_NeedDataSource)
'RadGrid1.ItemCommand += New GridCommandEventHandler(RadGrid1_ItemCommand)
'RadGrid1.ItemCreated += New GridItemEventHandler(RadGrid1_ItemCreated)
'RadGrid1.ID = "rgDemo"
RadGrid1.Width = Unit.Percentage(100)
RadGrid1.PageSize = 3
RadGrid1.AllowPaging = True
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric
RadGrid1.AutoGenerateColumns = False
RadGrid1.GroupingEnabled = True
RadGrid1.ShowGroupPanel = True
RadGrid1.ShowStatusBar = True
RadGrid1.ClientSettings.AllowDragToGroup = True
RadGrid1.DataSourceID = "sqldsGrid"
RadGrid1.Skin = "Outlook"
RadGrid1.MasterTableView.PageSize = 15
RadGrid1.MasterTableView.DataKeyNames = New String() {"SiteId"}
RadGrid1.MasterTableView.AllowAutomaticUpdates = True
'RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template
RadGrid1.MasterTableView.EditMode = GridEditMode.InPlace
'Dim gtc As New GridTemplateColumn()
'gtc.ItemTemplate = New ItemTemplateLabels("Description")
'gtc.HeaderText = "Description"
'gtc.EditItemTemplate = New EditItemTemplateTextBoxes("Description")
'RadGrid1.MasterTableView.Columns.Add(gtc)
'Dim gt2 As New GridTemplateColumn()
'gt2.ItemTemplate = New ItemTemplateLabels("Name")
'gt2.HeaderText = "Name"
'gt2.EditItemTemplate = New EditItemTemplateTextBoxes("Name")
'RadGrid1.MasterTableView.Columns.Add(gt2)
Dim boundColumn1 As New GridBoundColumn()
boundColumn1.DataField = "SiteId"
boundColumn1.UniqueName = "SiteId"
boundColumn1.HeaderText = "SiteId"
RadGrid1.MasterTableView.Columns.Add(boundColumn1)
Dim boundColumn2 As New GridBoundColumn()
boundColumn2.DataField = "SiteName"
boundColumn2.UniqueName = "SiteName"
boundColumn2.HeaderText = "SiteName"
RadGrid1.MasterTableView.Columns.Add(boundColumn2)
Dim gt3 As New GridTemplateColumn()
gt3.ItemTemplate = New ItemTemplateLinks("Links")
gt3.UniqueName = "EditCommandColumn"
gt3.HeaderText = "Links"
gt3.EditItemTemplate = New EditItemTemplateLinks("Links", "Update", "Update")
gt3.EditItemTemplate = New EditItemTemplateLinks("Links", "Cancel", "Cancel")
RadGrid1.MasterTableView.Columns.Add(gt3)
Dim gBtnColumn As New GridButtonColumn()
gBtnColumn.CommandName = "Delete"
gBtnColumn.Text = "Delete"
gBtnColumn.ButtonType = GridButtonColumnType.LinkButton
RadGrid1.MasterTableView.Columns.Add(gBtnColumn)
RadGrid1.MasterTableView.EditFormSettings.EditFormType = GridEditFormType.Template
phdrGrid.Controls.Add(RadGrid1)
End Sub
Private Class ItemTemplateLinks
Implements ITemplate
Protected rBtn As RadButton
Private colname As String = String.Empty
Private colValue As String = String.Empty
Public Sub New(ByVal cName As String)
colname = cName
End Sub
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
rBtn = New RadButton()
rBtn.Text = "Edit"
rBtn.ButtonType = RadButtonType.StandardButton
'rBtn.Command += New CommandEventHandler(rBtn_Command)
rBtn.CommandName = "Edit"
Dim rnd As New Random()
rBtn.ID = "test"
container.Controls.Add(rBtn)
End Sub
Private Sub rBtn_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim a As String = TryCast(sender, RadButton).CommandName
End Sub
End Class
Private Class EditItemTemplateLinks
Implements IBindableTemplate
Private lstItemType As ListItemType
Protected rBtn As RadButton
Protected rBtn1 As RadButton
Private colname As String = String.Empty
Private btnText As String = String.Empty
Private cmdName As String = String.Empty
Private colValue As String = String.Empty
Public Sub New(ByVal cName As String, ByVal bText As String, ByVal bCmdName As String)
btnText = bText
bCmdName = cmdName
colname = cName
End Sub
Private Sub rBtn_Command(ByVal sender As Object, ByVal e As CommandEventArgs)
Dim a As String = TryCast(sender, RadButton).CommandName
End Sub
Public Function ExtractValues(ByVal container As System.Web.UI.Control) As System.Collections.Specialized.IOrderedDictionary Implements System.Web.UI.IBindableTemplate.ExtractValues
Dim od As New OrderedDictionary()
Return od
End Function
Public Sub InstantiateIn(ByVal container As System.Web.UI.Control) Implements System.Web.UI.ITemplate.InstantiateIn
rBtn = New RadButton()
rBtn.Text = "Update"
rBtn.ButtonType = RadButtonType.StandardButton
rBtn.CommandName = "Update"
'rBtn.Command += New CommandEventHandler(rBtn_Command)
Dim rnd As New Random()
rBtn.ID = "ssss"
container.Controls.Add(rBtn)
rBtn1 = New RadButton()
rBtn1.Text = "Cancel"
rBtn1.ButtonType = RadButtonType.StandardButton
rBtn1.CommandName = "Cancel"
Dim rnd1 As New Random()
container.Controls.Add(rBtn1)
End Sub
End Class
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
End Class
When i click the Delete Button I am getting the Following error
Server Error in '/' Application.
Unable to cast object of type 'ItemTemplateLinks' to type 'System.Web.UI.IBindableTemplate'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.InvalidCastException: Unable to cast object of type 'ItemTemplateLinks' to type 'System.Web.UI.IBindableTemplate'.
Source Error:
An unhandled exception was generated during the execution of the current
web request. Information regarding the origin and location of the
exception can be identified using the exception stack trace below.
|
Stack Trace:
[InvalidCastException: Unable to cast object of type 'ItemTemplateLinks' to type 'System.Web.UI.IBindableTemplate'.] |
Version Information: Microsoft .NET Framework Version:2.0.50727.3623; ASP.NET Version:2.0.50727.3618