I'm developing a grid based largely on http://demos.telerik.com/aspnet-ajax/grid/examples/programming/commanditem/defaultcs.aspx
I need to be able to programatically abort inserting a record, and close the insert items template so that the user no longer sees the controls used for inserting. In the grid's ItemCommand, event, I want to do something like this:
I need to be able to programatically abort inserting a record, and close the insert items template so that the user no longer sees the controls used for inserting. In the grid's ItemCommand, event, I want to do something like this:
public void radGrid_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e){ switch (e.CommandName.ToString()) { case "PerformInsert": { //do something to determine if I can insert a record //if I can not insert a record //How do I close the insert items template?
I've tried e.Cancelled = true; but that doesn't seem to work. At this point, I successfully abort the insert, but the user continues to see the insert controls. She/he has to click the insert template's cancel button to close them.
Thanks!
Here's the grid markup:
<telerik:RadGrid runat="server" ID="rgDashboardGoals" AllowSorting="false" AllowAutomaticDeletes="true" GridLines="None" AllowFilteringByColumn="false" AllowPaging="true" Skin="Outlook" EnableViewState="true" AutoGenerateColumns="false" AllowAutomaticUpdates="true" PageSize="10" AllowMultiRowSelection="True" AllowMultiRowEdit="True" AllowAutomaticInserts="True" OnItemUpdated="rgDashboardGoals_ItemUpdated" OnItemCommand="rgDashboardGoals_ItemCommand" OnPageIndexChanged="rgDashboardGoals_PageChange" OnItemDataBound="rgDashboardGoals_ItemDataBound" StatusBarSettings-LoadingText="Loading..." OnNeedDataSource="LoadDashboardGoalsGrid"> <MasterTableView DataKeyNames="PartsDashboard_id,MonthYear" CommandItemDisplay="Top"> <CommandItemTemplate> <div style="padding: 5px 5px;"> Dashboard Goals grid management tools >> <asp:LinkButton ID="btnEditSelected" runat="server" CommandName="EditSelected" Visible='<%# rgDashboardGoals.EditIndexes.Count == 0 %>'> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/Edit.gif"/>Edit selected </asp:LinkButton> <asp:LinkButton ID="btnUpdateEdited" runat="server" CommandName="UpdateEdited" Visible='<%# rgDashboardGoals.EditIndexes.Count > 0 %>'> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/Update.gif"/>Update </asp:LinkButton> <asp:LinkButton ID="btnCancel" runat="server" CommandName="CancelAll" CausesValidation="false" Visible='<%# rgDashboardGoals.EditIndexes.Count > 0 || rgDashboardGoals.MasterTableView.IsItemInserted %>'> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/Cancel.gif"/>Cancel </asp:LinkButton> <asp:LinkButton ID="LinkButton2" runat="server" CommandName="InitInsert" Visible='<%# !rgDashboardGoals.MasterTableView.IsItemInserted %>'> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/AddNew.gif"/>Add new </asp:LinkButton> <asp:LinkButton ID="LinkButton3" runat="server" CommandName="PerformInsert" Visible='<%# rgDashboardGoals.MasterTableView.IsItemInserted %>'> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/Insert.gif"/> Add this goal record </asp:LinkButton> <asp:LinkButton ID="LinkButton1" OnClientClick="javascript:return confirm('Delete selected goal record(s)?')" runat="server" CommandName="DeleteSelected"> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/deleteRecord.gif"/>Delete selected goal records </asp:LinkButton> <asp:LinkButton ID="LinkButton4" runat="server" CommandName="RebindGrid"> <img style="border:0px;vertical-align:middle;" alt="" src="../Images/refreshGrid.gif"/>Refresh grid </asp:LinkButton> </div> </CommandItemTemplate> <Columns> <telerik:GridBoundColumn ReadOnly="true" UniqueName="Dealer_id" HeaderText="Dealer Code" SortExpression="Dealer_id" DataField="Dealer_id" /> <telerik:GridBoundColumn UniqueName="MonthYear" DataField="MonthYear" ReadOnly="true" HeaderText="Month/Year" SortExpression="MonthYear" /> <telerik:GridTemplateColumn ReadOnly="true" UniqueName="HinoOnlyGoal" SortExpression="HinoOnlyGoal" HeaderText="Hino Only Goal"> <ItemTemplate> <asp:Label ID="lblHinoOnlyGoal" Text='<%# Eval("HinoOnlyGoal").ToString() %>' runat="server" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="GoalMonthInsert" EditFormColumnIndex="0" Visible="false" HeaderText="Goal Month"> <InsertItemTemplate> <asp:DropDownList ID="ddlGoalMonth" runat="server" CssClass="hino_text"> <asp:ListItem Text="January" Value="1" /> <asp:ListItem Text="February" Value="2" /> <asp:ListItem Text="March" Value="3" /> <asp:ListItem Text="April" Value="4" /> <asp:ListItem Text="May" Value="5" /> <asp:ListItem Text="June" Value="6" /> <asp:ListItem Text="July" Value="7" /> <asp:ListItem Text="August" Value="8" /> <asp:ListItem Text="September" Value="9" /> <asp:ListItem Text="October" Value="10" /> <asp:ListItem Text="November" Value="11" /> <asp:ListItem Text="December" Value="12" /> </asp:DropDownList> </InsertItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="GoalYearInsert" EditFormColumnIndex="0" Visible="false" HeaderText="Goal Year"> <InsertItemTemplate> <asp:DropDownList ID="ddlGoalYear" runat="server" CssClass="hino_text"> <asp:ListItem Text="2013" Value="2013" /> <asp:ListItem Text="2014" Value="2014" /> <asp:ListItem Text="2015" Value="2015" /> <asp:ListItem Text="2016" Value="2016" /> <asp:ListItem Text="2017" Value="2017" /> <asp:ListItem Text="2018" Value="2018" /> </asp:DropDownList> </InsertItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="HinoOnlyGoalEdit" EditFormColumnIndex="0" Visible="false" HeaderText="Hino Only Goal"> <EditItemTemplate> <asp:TextBox ID="txtHinoOnlyGoal" runat="server" Text='<%# Eval("HinoOnlyGoal").ToString() %>' /> <asp:RequiredFieldValidator ID="rfvHinoOnlyGoal" ControlToValidate="txtHinoOnlyGoal" ErrorMessage="*- Required" runat="server" InitialValue="" /> <asp:RegularExpressionValidator ID="revHinoOnlyGoal" runat="server" ControlToValidate="txtHinoOnlyGoal" ErrorMessage="* - Must be a valid number. " ValidationExpression="[0-9]+(\.[0-9][0-9]?)?" /> </EditItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn ReadOnly="true" UniqueName="AllMakesGoal" SortExpression="AllMakesGoal" HeaderText="All Makes Goal"> <ItemTemplate> <asp:Label ID="lblAllMakesGoal" Text='<%# Eval("AllMakesGoal").ToString() %>' runat="server" /> </ItemTemplate> </telerik:GridTemplateColumn> <telerik:GridTemplateColumn UniqueName="AllMakesGoalEdit" EditFormColumnIndex="0" Visible="false" HeaderText="All Makes Goal"> <EditItemTemplate> <asp:TextBox ID="txtAllMakesGoal" runat="server" Text='<%# Eval("AllMakesGoal").ToString() %>' /> <asp:RequiredFieldValidator ID="rfvAllMakesGoal" ControlToValidate="txtAllMakesGoal" ErrorMessage="*- Required" runat="server" InitialValue="" /> <asp:RegularExpressionValidator ID="revAllMakesGoal" runat="server" ErrorMessage="* - Must be a valid number. " ControlToValidate="txtAllMakesGoal" ValidationExpression="[0-9]+(\.[0-9][0-9]?)?" /> </EditItemTemplate> </telerik:GridTemplateColumn> </Columns> <EditFormSettings ColumnNumber="3"> <FormTableItemStyle Wrap="False"></FormTableItemStyle> <FormCaptionStyle></FormCaptionStyle> <FormMainTableStyle GridLines="None" CellSpacing="0" CellPadding="3" Width="100%" /> <FormTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="2" Height="110px" Width="100%" /> <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle> <FormStyle Width="100%" BackColor="#eef2ea"></FormStyle> <EditColumn UniqueName="EditCommandColumn1" UpdateImageUrl="../Images/order.gif" CancelImageUrl="../Images/cancel.gif" ButtonType="ImageButton" /> <FormTableButtonRowStyle HorizontalAlign="Left"></FormTableButtonRowStyle> </EditFormSettings> </MasterTableView> <ClientSettings EnableRowHoverStyle="true"> <Selecting AllowRowSelect="True" /> </ClientSettings> </telerik:RadGrid>
e.Canceled =
true;
e.Canceled =
true;
e.Canceled =
true;