I like to keep all my code clean and thus I hate using datasources in my aspx pages. Instead I like to try and do it all via the codebehind. This however is posing a problem as I cannot delete records and I don't know where I am going wrong.
aspx
aspx.vb
aspx
| <telerik:RadGrid OnItemDeleted="RadGrid1_ItemDeleted" |
| OnItemUpdated="RadGrid1_ItemUpdated" |
| ID="RadGrid1" |
| runat="server" |
| Skin="Office2007" |
| AllowPaging="true" |
| AutoGenerateColumns="false" |
| AllowSorting="true" |
| AllowAutomaticDeletes="true" |
| AllowAutomaticUpdates="true"> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| <MasterTableView TableLayout="Auto" DataKeyNames="ID"> |
| <RowIndicatorColumn> |
| <HeaderStyle Width="20px" /> |
| </RowIndicatorColumn> |
| <ExpandCollapseColumn> |
| <HeaderStyle Width="20px" /> |
| </ExpandCollapseColumn> |
| <Columns> |
| <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" /> |
| <telerik:GridBoundColumn DataField="Title" HeaderText="Page Title" UniqueName="Title" Visible="true" ReadOnly="false" /> |
| <telerik:GridBoundColumn DataField="MenuName" HeaderText="Menu Name" UniqueName="MenuName" Visible="true" ReadOnly="false" /> |
| <telerik:GridTemplateColumn DataField="DateUpdated" HeaderText="Last Updated" UniqueName="DateUpdatedDisplay"> |
| <ItemTemplate> |
| <asp:Label ID="lblDateUpdated" runat="server" Text='<%# FormatDate(DataBinder.Eval(Container.DataItem, "DateUpdated")) %>' /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridTemplateColumn DataField="DateCreated" HeaderText="Date Created" UniqueName="DateCreatedDisplay"> |
| <ItemTemplate> |
| <asp:Label ID="lblDateCreated" runat="server" Text='<%# FormatDate(DataBinder.Eval(Container.DataItem, "DateCreated")) %>' /> |
| </ItemTemplate> |
| </telerik:GridTemplateColumn> |
| <telerik:GridBoundColumn DataField="UpdatedBy" HeaderText="Updated By" UniqueName="UpdatedBy" Visible="true" ReadOnly="true" /> |
| <telerik:GridBoundColumn DataField="isHomePage" HeaderText="Home Page" UniqueName="isHomePage" Visible="false" ReadOnly="false" /> |
| <telerik:GridBoundColumn DataField="MetaKeywords" HeaderText="Meta Keywords" UniqueName="MetaKeywords" Visible="false" ReadOnly="false" /> |
| <telerik:GridBoundColumn DataField="MetaDescription" HeaderText="Meta Description" UniqueName="MetaDescription" Visible="false" ReadOnly="false" /> |
| <telerik:GridButtonColumn ConfirmText="Delete this page?" ConfirmTitle="Delete" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn"> |
| <ItemStyle HorizontalAlign="Center" Width="50px" /> |
| </telerik:GridButtonColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
aspx.vb
| Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load |
| Dim PagesDC As New Dal.icms_PagesDataContext |
| Dim results = PagesDC.icms_Pages_GetPages |
| RadGrid1.DataSource = results |
| RadGrid1.DataBind() |
| End Sub |
| Protected Sub RadGrid1_ItemDeleted(ByVal source As Object, ByVal e As Telerik.Web.UI.GridDeletedEventArgs) Handles RadGrid1.ItemDeleted |
| Dim i As GridDataItem = DirectCast(e.Item, GridDataItem) |
| Dim ID As String = i.OwnerTableView.DataKeyValues(i.ItemIndex)("ID").ToString |
| Dim PagesDC As New Dal.icms_PagesDataContext |
| Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) |
| Dim results = PagesDC.icms_Pages_DeletePageByID(Convert.ToInt32(i)) |
| RadGrid1.Rebind() |
| End Sub |