I am using Rad Grid with a UserControl for the edit and insert form.
I have followed the code examples on the site and read the threads on the forum with people having a similar issue but I'm still having problems.
The ability to edit the items works properly. And when I click on the "Add new record" button the user control shows up properly, awaiting information and clicking of the insert button, but when I click on insert the command specified in the control properties for inserts never fires. I've used break points in page load and on the first instruction in the NewsList_InsertCommand function to ensure that a postback is occuring, and it is, but the NewsList_InsertCommand function never fires.
My Rad Grid Control:
My Insert Function in the code behind file:
My user control aspx file:
My user control code behind file.
I have followed the code examples on the site and read the threads on the forum with people having a similar issue but I'm still having problems.
The ability to edit the items works properly. And when I click on the "Add new record" button the user control shows up properly, awaiting information and clicking of the insert button, but when I click on insert the command specified in the control properties for inserts never fires. I've used break points in page load and on the first instruction in the NewsList_InsertCommand function to ensure that a postback is occuring, and it is, but the NewsList_InsertCommand function never fires.
My Rad Grid Control:
| <telerik:RadGrid ID="NewsList" AutoGenerateColumns="false" |
| runat="server" AllowFilteringByColumn="True" |
| AllowPaging="True" AllowSorting="True" |
| GridLines="None" Skin="Office2007" |
| OnNeedDataSource="NewsList_NeedDataSource" |
| OnUpdateCommand="NewsList_UpdateCommand" |
| PageSize="20" |
| OnItemDataBound="NewsList_ItemDataBound" |
| OnInsertCommand="NewsList_InsertCommand"> |
| <PagerStyle Mode="NextPrevAndNumeric" /> |
| <GroupingSettings CaseSensitive="False" /> |
| <ClientSettings> |
| <Selecting AllowRowSelect="True" /> |
| </ClientSettings> |
| <MasterTableView TableLayout="Auto" EditMode="EditForms" CommandItemDisplay="Top" InsertItemDisplay="Top" InsertItemPageIndexAction="ShowItemOnCurrentPage"> |
| <EditFormSettings EditFormType="WebUserControl" UserControlName="~/UserControls/News/NewsManagementEditControl.ascx"> |
| </EditFormSettings> |
| <Columns> |
| <telerik:GridBoundColumn AutoPostBackOnFilter="True" DataField="NewsId" |
| DataType="System.Int32" DefaultInsertValue="" HeaderText="News ID" |
| ShowFilterIcon="False" SortExpression="NewsId" UniqueName="NewsId" Visible="false"> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Title" DataField="Title" |
| UniqueName="Title" SortExpression="Title" |
| HeaderStyle-Width="450px" FilterControlWidth="450px" |
| AutoPostBackOnFilter="true" CurrentFilterFunction="Contains" |
| ShowFilterIcon="false"> |
| <HeaderStyle Width="450px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Date Created" DataField="DateCreated" |
| UniqueName="DateCreated" SortExpression="DateCreated" HeaderStyle-Width="50px" |
| FilterControlWidth="50px" AutoPostBackOnFilter="true" |
| CurrentFilterFunction="Contains" ShowFilterIcon="false"> |
| <HeaderStyle Width="50px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridBoundColumn HeaderText="Associated Apps" DataField="AssociatedApps" |
| UniqueName="AssociatedApps" HeaderStyle-Width="180px" ShowFilterIcon="false"> |
| <HeaderStyle Width="180px" /> |
| </telerik:GridBoundColumn> |
| <telerik:GridEditCommandColumn UpdateText="Update" CancelText="Cancel" UniqueName="Edit" ButtonType="LinkButton"> |
| </telerik:GridEditCommandColumn> |
| <telerik:GridButtonColumn CommandName="DeleteNews" |
| Text="Delete" UniqueName="column2"> |
| </telerik:GridButtonColumn> |
| </Columns> |
| </MasterTableView> |
| </telerik:RadGrid> |
My Insert Function in the code behind file:
| protected void NewsList_InsertCommand(object sender, GridCommandEventArgs e) |
| { |
| UserControl userControl = (UserControl)e.Item.FindControl(GridEditFormItem.EditFormUserControlID); |
| var newTitleControl = (RadTextBox)userControl.FindControl("txtTitle"); |
| var newDescriptionControl = (RadTextBox)userControl.FindControl("txtDescription"); |
| var newContentControl = (RadEditor)userControl.FindControl("txtNewsContent"); |
| if(String.IsNullOrEmpty(newTitleControl.Text) && String.IsNullOrEmpty(newDescriptionControl.Text) && String.IsNullOrEmpty(newContentControl.Text)) |
| { |
| return; |
| } |
| ONews newNewsItem = Engine.News(Globals.User.UserId).CreateNews(newTitleControl.Text, newDescriptionControl.Text, |
| newContentControl.Text, Globals.User.UserId); |
| var applicationListRepeater = (Repeater) userControl.FindControl("rptApplicationList"); |
| foreach (RepeaterItem app in applicationListRepeater.Items) |
| { |
| var checkbox = (CheckBox) app.FindControl("application"); |
| var applicationId = int.Parse(checkbox.Attributes["applicationId"]); |
| if (checkbox.Checked) |
| { |
| Engine.News(Globals.User.UserId).CreateApplicationNews(newNewsItem.NewsId, applicationId); |
| } |
| } |
My user control aspx file:
| <%@ Control Language="C#" AutoEventWireup="true" CodeBehind="NewsManagementEditControl.ascx.cs" Inherits="InternalAdmin.UserControls.News.NewsManagementEditControl" %> |
| <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> |
| <asp:UpdatePanel ID="EditNewsSection" runat="server"> |
| <ContentTemplate> |
| <table width="100%"> |
| <tr> |
| <td valign="top"> |
| <div class="Block"> |
| <div class="Block-tl"> |
| </div> |
| <div class="Block-tr"> |
| </div> |
| <div class="Block-bl"> |
| </div> |
| <div class="Block-br"> |
| </div> |
| <div class="Block-tc"> |
| </div> |
| <div class="Block-bc"> |
| </div> |
| <div class="Block-cl"> |
| </div> |
| <div class="Block-cr"> |
| </div> |
| <div class="Block-cc"> |
| </div> |
| <div class="Block-body"> |
| <div class="BlockHeader"> |
| <div class="t"> |
| News Item Details</div> |
| </div> |
| <div class="BlockContent"> |
| <div class="BlockContent-body"> |
| <table> |
| <tr> |
| <tr> |
| <td> |
| <asp:Label ID="lblNewsId" runat="server" Text=""></asp:Label> |
| </td> |
| </tr> |
| <td> |
| <strong>Title</strong> |
| </td> |
| <td rowspan="6" valign="top"> |
| <table> |
| <tr> |
| <td> |
| <strong> |
| Associated Applications |
| </strong> |
| </td> |
| </tr> |
| <asp:Repeater ID="rptApplicationList" runat="server" OnItemDataBound="rptApplicationList_ItemDataBound"> |
| <ItemTemplate> |
| <tr> |
| <td> |
| <asp:CheckBox ID="application" Text="" runat="server"/> |
| </td> |
| </tr> |
| </ItemTemplate> |
| </asp:Repeater> |
| </table> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <telerik:RadTextBox ID="txtTitle" MaxLength="200" runat="server"> |
| </telerik:RadTextBox> |
| <br /> |
| <br /> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <strong>Description</strong> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <telerik:RadTextBox ID="txtDescription" MaxLength="500" runat="server"> |
| </telerik:RadTextBox> |
| <br /> |
| <br /> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <strong>News Content</strong> |
| </td> |
| </tr> |
| <tr> |
| <td> |
| <telerik:RadEditor ID="txtNewsContent" runat="server" Height="300px" |
| Width="500px" EditModes="Design" |
| ToolbarMode="Default" StripFormattingOnPaste="AllExceptNewLines"> |
| <CssFiles> |
| <telerik:EditorCssFile Value="~/CSS/Editor.css" /> |
| </CssFiles> |
| <tools> |
| <telerik:EditorToolGroup> |
| <telerik:EditorTool Name="Bold" /> |
| <telerik:EditorTool Name="Underline" /> |
| <telerik:EditorSeparator /> |
| <telerik:EditorTool Name="Cut" /> |
| <telerik:EditorTool Name="Copy"/> |
| <telerik:EditorTool Name="Paste"/> |
| <telerik:EditorSeparator /> |
| <telerik:EditorTool Name="Undo" /> |
| <telerik:EditorTool Name="Redo"/> |
| </telerik:EditorToolGroup> |
| </tools> |
| </telerik:RadEditor> |
| </td> |
| </tr> |
| <tr> |
| <td align="left"> |
| <asp:Button ID="btnUpdate" runat="server" Text="Update" CommandName="Update" Visible='<%# !(DataItem is GridInsertionObject) %>' /> |
| <asp:Button ID="btnInsert" runat="server" Text="Insert" CommandName="Insert" Visible='<%# DataItem is GridInsertionObject %>' /> |
| |
| <asp:Button ID="btnCancel" runat="server" Text="Cancel" CommandName="Cancel" CausesValidation="false" /> |
| </td> |
| </tr> |
| </table> |
| </div> |
| </div> |
| </div> |
| </div> |
| </td> |
| </tr> |
| </table> |
| </ContentTemplate> |
| </asp:UpdatePanel> |
My user control code behind file.
| namespace InternalAdmin.UserControls.News |
| { |
| public partial class NewsManagementEditControl : System.Web.UI.UserControl |
| { |
| private List<OApplicationNews> ApplicationNews |
| { |
| get |
| { |
| object o = Session["_ApplicationNews"]; |
| if (o == null) |
| return new List<OApplicationNews>(); |
| else |
| { |
| return (List<OApplicationNews>)o; |
| } |
| } |
| } |
| private object _dataItem = null; |
| public object DataItem |
| { |
| get |
| { |
| return this._dataItem; |
| } |
| set |
| { |
| this._dataItem = value; |
| } |
| } |
| protected void Page_Load(object sender, EventArgs e) |
| { |
| } |
| protected void rptApplicationList_ItemDataBound(object sender, RepeaterItemEventArgs e) |
| { |
| var data = (OApplication)e.Item.DataItem; |
| var applicationControl = (CheckBox)e.Item.FindControl("application"); |
| applicationControl.Text = data.ApplicationName; |
| applicationControl.Attributes["applicationId"] = data.ApplicationId.ToString(); |
| var applicationNewsId = |
| ApplicationNews.Where(id => id.ApplicationId == data.ApplicationId); |
| if (applicationNewsId.Count() > 0) |
| { |
| applicationControl.Attributes["applicationNewsId"] = |
| applicationNewsId.Select(id => id.ApplicationNewsId).First().ToString(); |
| applicationControl.Checked = true; |
| } |
| } |
| } |
| } |