Popup should remain open after clicking Save in a RadGrid popup

18 posts, 0 answers
  1. Pradeep Enugala
    Pradeep Enugala avatar
    55 posts
    Member since:
    Apr 2010

    Posted 13 May 2010 Link to this post

    I have a RadGrid (Grid1) with Master table edit mode = popup. I have the following code in the commandItemTemplate. The popup is a user control.The popup has some textboxes and another Grid (Grid2).
    <CommandItemTemplate> 
                                        <table width="100%" border="0" cellspacing="0" cellpadding="0"
                                            <tr style="height: 20px"
                                                <td style="width: 100%; color: #074768" align="right"
                                                    <asp:LinkButton ID="lnkBtnAddLocation" runat="server" CommandName="InitInsert" Style="font-weight: bold;
                                                        padding-right: 2px; color: #074768;"
                                                        <asp:ImageButton ID="imgbtn_AddLocation" runat="server" SkinID="AddRecord" CommandName="InitInsert" /> 
                                                        Add Location 
                                                    </asp:LinkButton> 
                                                </td> 
                                            </tr> 
                                        </table> 
    </CommandItemTemplate> 

    If I click on "Add Location" it opens a popup. I enter some data and when I click on save, It closes the popup and inserts the data in the RadGrid. But I want the popup to remain open. This is because I want to have a Save button for saving the textboxes data to Grid1 and a OK button for saving the selections in the Grid2 to the Grid1.

    Is it possible to keep the popup open after Inserting data into Grid1?
  2. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 13 May 2010 Link to this post

    Hello Pradeep,

    Here is the code for keeping the pop-insert form:
    protected void Page_Load(object sender, EventArgs e)
    {
        RadGrid1.ItemInserted += new GridInsertedEventHandler(RadGrid1_ItemInserted);
    }
    protected void RadGrid1_ItemInserted(object source, GridInsertedEventArgs e)
    {
        e.KeepInInsertMode = true;
    }

    Hope it helps.

    All the best,
    Tsvetoslav
    the Telerik team

    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 23 Sep 2010 Link to this post

    Hello,

    I am trying to do the same thing but when I put that code in the Page_Load, I get two errors highlighted in the environment.

    1. 'Public Event ItemInserted(source As Object, e As Telerik.Web.UI.GridInsertedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

    2. Delegate 'Telerik.Web.UI.GridInsertedEventHandler' requires and 'AddressOf' expression or lambda expression as the only argument to its constructor.

    Thanks,

    Steve
  5. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 29 Sep 2010 Link to this post

    Hello Stephen,

    My code snippet is in C# and you evidently are programming in VB. Here is the code in VB:

    Protected Sub Page_Load(sender As Object, e As EventArgs)
        RadGrid1.ItemInserted += New GridInsertedEventHandler(AddressOf RadGrid1_ItemInserted)
    End Sub
    Protected Sub RadGrid1_ItemInserted(source As Object, e As GridInsertedEventArgs)
        e.KeepInInsertMode = True
    End Sub

    Hope it helps.

    Greetings,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  6. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 29 Sep 2010 Link to this post

    Hello,

    I had converted the code to VB first...but the code converter didn't give me the 'AddressOf ' so I added that in and it solved the second error.  But I am still getting the first error:

    'Public Event ItemInserted(source As Object, e As Telerik.Web.UI.GridInsertedEventArgs)' is an event, and cannot be called directly. Use a 'RaiseEvent' statement to raise an event.

    How do I use the RaiseEvent statement with this as it seems it doesn't like me calling it as is?

    thanks,

    Steve
  7. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 05 Oct 2010 Link to this post

    Hi Stephen,

    The error states that somewhere in your code you have a statement such as the one below:

    ItemInserted(....)

    where as you cannot call event delegates in this way as they will automatically triggered by the framework. Could you paste you complete code-behind?

    Regards,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  8. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 05 Oct 2010 Link to this post

    Hello,

    The only place that appears is the two places you designated:

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim cRegistration As New CRegistration
        hidRegistrationID.Value = DirectCast(Me.Parent.NamingContainer, GridNestedViewItem).ParentItem.GetDataKeyValue("RegistrationID").ToString()
        cRegistration.LoadRegistrationTypeID(HttpContext.Current.Session("UserID").ToString, hidRegistrationID.Value)
        hidRegistrationTypeID.Value = cRegistration.RegistrationTypeID.ToString
        gvOrders.ItemInserted += New GridInsertedEventHandler(AddressOf gvOrders_ItemInserted)
    End Sub

    Protected Sub gvOrders_ItemInserted(ByVal source As Object, ByVal e As GridInsertedEventArgs)
        e.KeepInInsertMode = True
    End Sub

    Thanks,

    Steve
  9. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 08 Oct 2010 Link to this post

    Hi Stephen,

    The code seems all right. Still expecting the complete code-behind. You can also add the aspx. Thanks for that.

    Regards,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  10. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 08 Oct 2010 Link to this post

    Ok here is the complete codebehind:

    Imports WorkshopsLibrary
    Imports Telerik.Web.UI
      
    Partial Public Class orders
        Inherits System.Web.UI.UserControl
      
        Protected WithEvents gvAddOns As GridView
        Protected WithEvents rblRequiredRegistration As RadioButtonList
        Protected bAddOnsChecked As Boolean = False
        Protected iExhibitorAttendeesIncluded As Integer
        Protected bRegistrationLateFee As Boolean
        Protected dRegistrationLateFeeDeadline As Date
        Protected bRegistered As Boolean = False
        Protected iAllowableTotal As Integer
        Protected iUnallowableTotal As Integer
        Protected iTotal As Integer
      
        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
      
            Dim cRegistration As New CRegistration
      
            hidRegistrationID.Value = DirectCast(Me.Parent.NamingContainer, GridNestedViewItem).ParentItem.GetDataKeyValue("RegistrationID").ToString()
      
            cRegistration.LoadRegistrationTypeID(HttpContext.Current.Session("UserID").ToString, hidRegistrationID.Value)
            hidRegistrationTypeID.Value = cRegistration.RegistrationTypeID.ToString
      
            gvOrders.ItemInserted += New GridInsertedEventHandler(AddressOf gvOrders_ItemInserted)
      
        End Sub
      
        Private Function CustomValidation(ByVal e As Telerik.Web.UI.GridCommandEventArgs) As Boolean
      
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim gvAddOns As GridView = CType(editedItem.FindControl("gvAddOns"), GridView)
            Dim lblStatus As Label = CType(editedItem.FindControl("lblStatus"), Label)
            Dim bValid As Boolean = True
            Dim bMismatchItem As Boolean = False
            Dim bMismatchQuantity As Boolean = False
      
            For Each row As GridViewRow In gvAddOns.Rows
                Dim chkItem As CheckBox = CType(row.FindControl("chkItem"), CheckBox)
                Dim txtQuantity As TextBox = CType(row.FindControl("txtQuantity"), TextBox)
                If (chkItem IsNot Nothing) And (chkItem.Checked) Then
                    If txtQuantity.Text = "" Then
                        bMismatchItem = True
                    End If
                Else
                    If txtQuantity.Text <> "" Then
                        bMismatchQuantity = True
                    End If
                End If
            Next
      
            If bMismatchItem Then
                bValid = False
                lblStatus.Text = "Error: You must enter the quantity for the item you selected."
                lblStatus.Visible = True
            End If
      
            If bMismatchQuantity Then
                bValid = False
                lblStatus.Text = "Error: You must check the item for which you have entered a quantity."
                lblStatus.Visible = True
            End If
      
            Return bValid
      
        End Function
      
        Protected Sub gvAddOns_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvAddOns.RowDataBound
      
            If e.Row.DataItem Is Nothing Then Exit Sub
      
            If e.Row.RowType = DataControlRowType.DataRow Then
                Dim sID As String = DataBinder.Eval(e.Row.DataItem, "ID").ToString()
                Dim sDescription As String = DataBinder.Eval(e.Row.DataItem, "Description").ToString()
                Dim chkItem As CheckBox = CType(e.Row.FindControl("chkItem"), CheckBox)
                Dim txtQuantity As TextBox = CType(e.Row.FindControl("txtQuantity"), TextBox)
                Dim txtPrice As TextBox = CType(e.Row.FindControl("txtPrice"), TextBox)
      
                Dim cCatalog As New CCatalog
                cCatalog.LoadBundle(HttpContext.Current.Session("UserID").ToString, sID)
                txtPrice.Text = cCatalog.BundlePrice.ToString
      
                If hidRegistrationTypeID.Value = "3" Then
                    Dim cExhibitors As New CExhibitors
                    Dim dsAttendees As DataSet = cExhibitors.dsAttendeeList(HttpContext.Current.Session("UserID").ToString, hidRegistrationID.Value, HttpContext.Current.Session("AdminWorkshopID").ToString)
                    Dim iAttendeeCount As Integer = dsAttendees.Tables(0).Rows.Count
                    If sDescription = "Additional Attendee" Then
                        If iAttendeeCount > iExhibitorAttendeesIncluded Then
                            If Not bRegistered Then
                                chkItem.Checked = True
                                txtQuantity.Text = CStr(iAttendeeCount - iExhibitorAttendeesIncluded)
                            End If
                        End If
                    End If
                End If
      
                If sDescription = "Late Fee" Then
                    If bRegistrationLateFee Then
                        If (DateDiff(DateInterval.Day, CDate(FormatDateTime(Now, DateFormat.ShortDate)), CDate(FormatDateTime(dRegistrationLateFeeDeadline, DateFormat.ShortDate))) < 1) Then
                            If Not bRegistered Then
                                chkItem.Checked = True
                                txtQuantity.Text = "1"
                            End If
                        End If
                    End If
                    e.Row.Visible = False
                End If
            End If
      
        End Sub
      
        Private Sub gvOrders_DetailTableDataBind(ByVal source As Object, ByVal e As GridDetailTableDataBindEventArgs) Handles gvOrders.DetailTableDataBind
      
            Dim dataItem As GridDataItem = CType(e.DetailTableView.ParentItem, GridDataItem)
            Select Case e.DetailTableView.Name
                Case "OrderSummary"
                    odsOrderSummaryList.SelectParameters("OrderID").DefaultValue = dataItem.GetDataKeyValue("ID").ToString()
            End Select
      
        End Sub
      
        Private Sub gvOrders_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvOrders.InsertCommand
      
            If e.CommandName = RadGrid.PerformInsertCommandName Then
                If CustomValidation(e) Then
                    Dim cRegistration As New CRegistration
                    Dim iRet As Integer
                    Dim bRet As Boolean = False
                    Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
      
                    iRet = cRegistration.AddOrder(HttpContext.Current.Session("UserID").ToString, hidRegistrationID.Value, HttpContext.Current.Session("AdminWorkshopID").ToString)
      
                    Dim rblRequiredRegistration As RadioButtonList = CType(editedItem.FindControl("rblRequiredRegistration"), RadioButtonList)
                    Dim txtPrice As TextBox = CType(editedItem.FindControl("txtPrice"), TextBox)
                    Dim gvAddOns As GridView = CType(editedItem.FindControl("gvAddOns"), GridView)
      
                    If iRet > 0 Then
                        bRet = cRegistration.AddUpOrderItemOverride(HttpContext.Current.Session("UserID").ToString, _
                                                                    iRet.ToString, _
                                                                    rblRequiredRegistration.SelectedValue, _
                                                                    "1", _
                                                                    txtPrice.Text)
      
                        If bRet Then
                            For Each row As GridViewRow In gvAddOns.Rows
                                Dim chkItem As CheckBox = CType(row.FindControl("chkItem"), CheckBox)
                                Dim txtQuantity As TextBox = CType(row.FindControl("txtQuantity"), TextBox)
                                Dim txtAddOnPrice As TextBox = CType(row.FindControl("txtPrice"), TextBox)
                                If chkItem IsNot Nothing AndAlso chkItem.Checked Then
                                    bRet = cRegistration.AddUpOrderItemOverride(HttpContext.Current.Session("UserID").ToString, _
                                                                                    iRet.ToString, _
                                                                                    gvAddOns.DataKeys(row.RowIndex).Value.ToString, _
                                                                                    txtQuantity.Text, _
                                                                                    txtAddOnPrice.Text)
                                    If Not bRet Then
                                        Exit For
                                    End If
                                End If
                            Next
                            If bRet Then
                                gvOrders.DataBind()
                            Else
                                gvOrders.Controls.Add(New LiteralControl("<strong>Save add-ons failed!</strong>"))
                            End If
                        Else
                            gvOrders.Controls.Add(New LiteralControl("<strong>Save registration failed!</strong>"))
                        End If
                    Else
                        gvOrders.Controls.Add(New LiteralControl("<strong>Add Order failed!</strong>"))
                    End If
                End If
            End If
      
        End Sub
      
        Private Sub gvOrders_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvOrders.ItemCommand
      
            If e.CommandName = RadGrid.EditCommandName Then
                e.Item.OwnerTableView.EditMode = GridEditMode.InPlace
            End If
            If e.CommandName = RadGrid.InitInsertCommandName Then
                e.Item.OwnerTableView.EditMode = GridEditMode.PopUp
            End If
      
        End Sub
      
        Protected Sub gvOrders_ItemInserted(ByVal source As Object, ByVal e As GridInsertedEventArgs)
      
            e.KeepInInsertMode = True
      
        End Sub
      
      
        Private Sub gvOrders_UpdateCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvOrders.UpdateCommand
      
            Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
            Dim editMan As GridEditManager = editedItem.EditManager
      
            Dim column As GridColumn
      
            For Each column In e.Item.OwnerTableView.Columns
                If TypeOf column Is IGridEditableColumn Then
                    Dim editableCol As IGridEditableColumn = CType(column, IGridEditableColumn)
                    If (editableCol.IsEditable) Then
                        Dim editor As IGridColumnEditor = editMan.GetColumnEditor(editableCol)
      
                        Dim editorType As String = CType(editor, Object).ToString()
                        Dim editorText As String = "unknown"
                        Dim editorValue As Object = Nothing
      
                        If (TypeOf editor Is GridBoolColumnEditor) Then
                            editorText = CType(editor, GridBoolColumnEditor).Value.ToString()
                            editorValue = CType(editor, GridBoolColumnEditor).Value
                        End If
      
                        Dim cRegistration As New CRegistration
                        Dim iRet As Integer = cRegistration.UpdateOrder(HttpContext.Current.Session("UserID").ToString, _
                                                                        editedItem.OwnerTableView.DataKeyValues(editedItem.ItemIndex)("ID").ToString, _
                                                                        CBool(editorValue), _
                                                                        HttpContext.Current.Session("AdminWorkshopID").ToString)
                        If iRet <> 0 Then
                            gvOrders.DataBind()
                        Else
                            gvOrders.Controls.Add(New LiteralControl("<strong>Save Failed!</strong>"))
                        End If
                    End If
                End If
            Next
      
        End Sub
      
        Private Sub rblRequiredRegistration_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles rblRequiredRegistration.SelectedIndexChanged
      
            Dim cCatalog As New CCatalog
            Dim editForm As GridEditFormItem = DirectCast(rblRequiredRegistration.NamingContainer, GridEditFormItem)
            Dim txtPrice As TextBox = DirectCast(editForm.FindControl("txtPrice"), TextBox)
      
            cCatalog.LoadBundle(HttpContext.Current.Session("UserID").ToString, rblRequiredRegistration.SelectedValue)
            txtPrice.Text = cCatalog.BundlePrice.ToString
      
        End Sub
      
    End Class

    This is actually a user control so here is the complete ascx:

    <%@ Control Language="vb" AutoEventWireup="false" CodeBehind="orders.ascx.vb" Inherits="WorkshopsAdmin.orders" %>
      
    <%@ Register TagPrefix="telerik" Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI"  %>       
         
        <asp:HiddenField ID="hidRegistrationID" runat="server" />
        <asp:HiddenField ID="hidRegistrationTypeID" runat="server" />
         
        <asp:Panel ID="pnlBottomPanel" runat="server" CssClass="tab_panel"
               
        <telerik:RadGrid ID="gvOrders" DataSourceID="odsOrderList" runat="server" AutoGenerateColumns="False" PageSize="20" GridLines="None" Skin="Office2007">
            <PagerStyle Mode="NextPrevAndNumeric" />
            <MasterTableView DataSourceID="odsOrderList" DataKeyNames="ID" EditMode="InPlace" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText="Add Order">
                <DetailTables>
                    <telerik:GridTableView CssClass="detail_table" DataSourceID="odsOrderSummaryList" DataKeyNames="ID" Name="OrderSummary" AutoGenerateColumns="false" Width="100%" ShowFooter="True">
                        <Columns>
                            <telerik:GridBoundColumn SortExpression="Description" HeaderText="Item" HeaderButtonType="TextButton" DataField="Description" UniqueName="Description" />
                            <telerik:GridBoundColumn SortExpression="Price" HeaderText="Price" HeaderButtonType="TextButton" DataField="Price" UniqueName="Price" DataFormatString="{0:C}" />                        
                            <telerik:GridBoundColumn SortExpression="OverridePrice" HeaderText="Override Price" HeaderButtonType="TextButton" DataField="OverridePrice" UniqueName="OverridePrice" DataFormatString="{0:C}" />
                            <telerik:GridBoundColumn SortExpression="Quantity" HeaderText="Quantity" HeaderButtonType="TextButton" DataField="Quantity" UniqueName="Quantity" />
                            <telerik:GridBoundColumn SortExpression="LineItemTotalAllowable" HeaderText="Allowable" FooterText="Allowable Total: " HeaderButtonType="TextButton" DataField="LineItemTotalAllowable" UniqueName="LineItemTotalAllowable" Aggregate="Sum" DataFormatString="{0:C}" />                        
                            <telerik:GridBoundColumn SortExpression="LineItemTotalUnallowable" HeaderText="Unallowable" FooterText="Unallowable Total: " HeaderButtonType="TextButton" DataField="LineItemTotalUnallowable" UniqueName="LineItemTotalUnallowable" Aggregate="Sum" DataFormatString="{0:C}" />                        
                            <telerik:GridBoundColumn SortExpression="LineItemTotal" HeaderText="Totals" FooterText="Order Total: " HeaderButtonType="TextButton" DataField="LineItemTotal" UniqueName="LineItemTotal" Aggregate="Sum" DataFormatString="{0:C}" />                                                
                        </Columns>
                    </telerik:GridTableView>
                </DetailTables>
                <Columns>
                    <telerik:GridEditCommandColumn ButtonType="ImageButton" UniqueName="EditCommandColumn" />
                    <telerik:GridBoundColumn SortExpression="ID" HeaderText="Order ID" HeaderButtonType="TextButton" DataField="ID" UniqueName="ID" ReadOnly="true" />
                    <telerik:GridBoundColumn SortExpression="Cost" HeaderText="Cost" HeaderButtonType="TextButton" DataField="Cost" UniqueName="Cost" DataFormatString="{0:C}" ReadOnly="true" />
                    <telerik:GridCheckBoxColumn SortExpression="Cancelled" HeaderText="Cancelled" HeaderButtonType="TextButton" DataField="Cancelled" UniqueName="Cancelled" />
                    <telerik:GridBoundColumn SortExpression="Timestamp" HeaderText="Timestamp" HeaderButtonType="TextButton" DataField="Timestamp" UniqueName="Timestamp" ReadOnly="true" />                                                
                </Columns>
                <NoRecordsTemplate>
                    <p class="status">There are no orders for this registration.</p>
                </NoRecordsTemplate>            
                <EditFormSettings EditFormType="Template">
                    <FormTemplate>
                        <asp:ObjectDataSource ID="odsRequiredCatalogList" runat="server" SelectMethod="dsCatalogList" TypeName="WorkshopsLibrary.CRegistration">
                            <SelectParameters>
                                <asp:SessionParameter Name="sUserID" SessionField="UserID" Type="String" />
                                <asp:ControlParameter Name="sRegistrationTypeID" ControlID="hidRegistrationTypeID" Type="String" />
                                <asp:Parameter Name="bRequired" DefaultValue="True" Type="Boolean" />
                                <asp:SessionParameter Name="sWorkshopID" SessionField="AdminWorkshopID" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>                            
                        <p>Please choose one of the registration options below.</p>
                        <asp:RadioButtonList ID="rblRequiredRegistration" runat="server" DataSourceID="odsRequiredCatalogList" DataValueField="ID" DataTextField="Description" AutoPostBack="true">
                        </asp:RadioButtonList>
                        <asp:RequiredFieldValidator ID="rfvRequiredRegistration" ControlToValidate="rblRequiredRegistration" runat="server" ErrorMessage=" * Required" CssClass="required" />
                        <br />
                        Price: <asp:TextBox ID="txtPrice" runat="server"></asp:TextBox>
                        <br />
                        <asp:ObjectDataSource ID="odsCatalogList" runat="server" SelectMethod="dsCatalogList" TypeName="WorkshopsLibrary.CRegistration">
                            <SelectParameters>
                                <asp:SessionParameter Name="sUserID" SessionField="UserID" Type="String" />
                                <asp:ControlParameter Name="sRegistrationTypeID" ControlID="hidRegistrationTypeID" Type="String" />
                                <asp:Parameter Name="bRequired" DefaultValue="False" Type="String" />
                                <asp:SessionParameter Name="sWorkshopID" SessionField="AdminWorkshopID" Type="String" />
                            </SelectParameters>
                        </asp:ObjectDataSource>                                
                        <asp:GridView ID="gvAddOns" runat="server" DataSourceID="odsCatalogList" AutoGenerateColumns="False" CellPadding="8" GridLines="None" DataKeyNames="ID" OnRowDataBound="gvAddOns_RowDataBound">
                            <Columns>
                                <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:CheckBox ID="chkItem" runat="server" />
                                    </ItemTemplate>
                                    <HeaderStyle Width="30px" />
                                </asp:TemplateField
                                <asp:BoundField DataField="Description" HeaderText="Item" HeaderStyle-HorizontalAlign="Left" />
                                <asp:TemplateField HeaderText="Quantity">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtQuantity" runat="server" Width="30px" MaxLength="4" />
                                    </ItemTemplate>
                                    <HeaderStyle Width="30px" />
                                </asp:TemplateField>
                                <asp:TemplateField HeaderText="Price">
                                    <ItemTemplate>
                                        <asp:TextBox ID="txtPrice" runat="server" Width="80px" />
                                    </ItemTemplate>
                                    <HeaderStyle Width="80px" />
                                </asp:TemplateField>             
                            </Columns>
                        </asp:GridView>
                        <asp:Label ID="lblStatus" runat="server" CssClass="required" Visible="false" />
                        <asp:Button ID="cmdAdd" runat="server" Text="Save" CommandName="PerformInsert" />                    
                    </FormTemplate>
                </EditFormSettings>            
            </MasterTableView>          
        </telerik:RadGrid
          
        <asp:ObjectDataSource ID="odsOrderList" runat="server" SelectMethod="dsOrderListByRID" TypeName="WorkshopsLibrary.CRegistration">
            <SelectParameters>
                <asp:SessionParameter Name="UserID" SessionField="UserID" Type="String" />
                <asp:ControlParameter Name="RegistrationID" ControlID="hidRegistrationID" Type="String" />
                <asp:SessionParameter Name="WorkshopID" SessionField="AdminWorkshopID" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>
          
        <asp:ObjectDataSource ID="odsOrderSummaryList" runat="server" SelectMethod="dsOrderSummaryList" TypeName="WorkshopsLibrary.CRegistration">
            <SelectParameters>
                <asp:SessionParameter Name="UserID" SessionField="UserID" Type="String" />
                <asp:Parameter Name="OrderID" Type="String" />
                <asp:SessionParameter Name="WorkshopID" SessionField="AdminWorkshopID" Type="String" />
            </SelectParameters>
        </asp:ObjectDataSource>     
          
          
        </asp:Panel>
  11. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 14 Oct 2010 Link to this post

    Hello Pradeep,

    Sorry for having sent you the wrong syntax for the addition of the event handler. The correct one in VB.NET is:
    AddHandler gvOrders.ItemInserted, AddressOf gvOrders_ItemInserted

    Hope this will finally fix the exception at hand.

    Regards,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  12. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 14 Oct 2010 Link to this post

    Hello again,

    Thank you.  That code cleared up my exception...but the gvOrders_ItemInserted method is still never being called so it does not remain in edit mode.  I tried adding the OnItemInserted="gvOrders_ItemInserted" to the grid and that didn't help either.

    When would it reach the ItemInserted method?  When it the item considered inserted?  Is it after the InsertCommand method is executed?  I am getting that far.  It executes the InsertCommand method but never hits the ItemInserted method.

    Thanks,

    Steve
  13. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 20 Oct 2010 Link to this post

    Hi Stephen,

    The ItemInserted event is thrown only if the item is inserted. It happens always after the InsertCommand : the InsertCommand event marks the beginning of the operation and the ItemInserted one - its successful end. Please, check if your item is inserted all right into the underlying data store - I suspect this must be the reason.

    Regards,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  14. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 20 Oct 2010 Link to this post

    Hello,

    Well that sort of explains the issue I am having.  Here is the code of my InsertCommand:

    Private Sub gvOrders_InsertCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles gvOrders.InsertCommand
        If e.CommandName = RadGrid.PerformInsertCommandName Then
            If CustomValidation(e) Then
                Dim cRegistration As New CRegistration
                Dim iRet As Integer
                Dim bRet As Boolean = False
                Dim editedItem As GridEditableItem = CType(e.Item, GridEditableItem)
                iRet = cRegistration.AddOrder(HttpContext.Current.Session("UserID").ToString, hidRegistrationID.Value, HttpContext.Current.Session("AdminWorkshopID").ToString)
                Dim rblRequiredRegistration As RadioButtonList = CType(editedItem.FindControl("rblRequiredRegistration"), RadioButtonList)
                Dim txtPrice As TextBox = CType(editedItem.FindControl("txtPrice"), TextBox)
                Dim gvAddOns As GridView = CType(editedItem.FindControl("gvAddOns"), GridView)
                If iRet > 0 Then
                    bRet = cRegistration.AddUpOrderItemOverride(HttpContext.Current.Session("UserID").ToString, _
                                                                iRet.ToString, _
                                                                rblRequiredRegistration.SelectedValue, _
                                                                "1", _
                                                                txtPrice.Text)
                    If bRet Then
                        For Each row As GridViewRow In gvAddOns.Rows
                            Dim chkItem As CheckBox = CType(row.FindControl("chkItem"), CheckBox)
                            Dim txtQuantity As TextBox = CType(row.FindControl("txtQuantity"), TextBox)
                            Dim txtAddOnPrice As TextBox = CType(row.FindControl("txtPrice"), TextBox)
                            If chkItem IsNot Nothing AndAlso chkItem.Checked Then
                                bRet = cRegistration.AddUpOrderItemOverride(HttpContext.Current.Session("UserID").ToString, _
                                                                                iRet.ToString, _
                                                                                gvAddOns.DataKeys(row.RowIndex).Value.ToString, _
                                                                                txtQuantity.Text, _
                                                                                txtAddOnPrice.Text)
                                If Not bRet Then
                                    Exit For
                                End If
                            End If
                        Next
                        If bRet Then
                            gvOrders.DataBind()
                        Else
                            gvOrders.Controls.Add(New LiteralControl("<strong>Save add-ons failed!</strong>"))
                        End If
                    Else
                        gvOrders.Controls.Add(New LiteralControl("<strong>Save registration failed!</strong>"))
                    End If
                Else
                    gvOrders.Controls.Add(New LiteralControl("<strong>Add Order failed!</strong>"))
                End If
            End If
        End If
    End Sub

    Since I am using custom code to perform the insert, do I need to return something to show that the item was successfully inserted because the ItemInserted is never fired, even when the item was successfully inserted.

    But what I am trying to do actually is keep it in edit mode when it fails on my CustomValidation method that is called within the InsertCommand shown above.

    thanks,

    Steve
  15. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 26 Oct 2010 Link to this post

    Hi Stephen,

    The ItemInserted event is designed to work only with DataSource controls when those are connected to the grid. In other words, it is just a convenience that lets the developer know whether the DataSource control has performed the CRUD operation successfully or not.

    However, when you are performing the CRUD operations manually as in your case you do not have a need for the ItemInserted event as you directly know whether you have inserted the new item into the collection or not. That is, the moment you call cRegistration.AddUpOrderItemOverride or cRegistration.AddOrder  you know that the item has been inserted. If you are afraid that some exception might be thrown by those custom methods, you might surround their call location with a try and catch block. If the catch block is hit, then you will know that something has gone wrong and can take action accordingly.

    Greetings,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  16. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 26 Oct 2010 Link to this post

    Hello,

    Ok that sounds like a plan, my only question now is when I am catching the exception of my custom AddOrder method within the grid InsertCommand method, how do I do the KeepInInsertMode so my edit form doesn't close?  The KeepInInsertMode is not a member of GridCommandEventArgs.

    thanks,

    Steve
  17. Tsvetoslav
    Admin
    Tsvetoslav avatar
    1823 posts

    Posted 26 Oct 2010 Link to this post

    Hello Stephen,

    You need to use to set e.Canceled = true as this will effectively keep the insert form open and prevent the grid from rebinding.

    Hope it helps.

    All the best,
    Tsvetoslav
    the Telerik team
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
  18. Stephen
    Stephen avatar
    158 posts
    Member since:
    Jan 2009

    Posted 26 Oct 2010 Link to this post

    YES!!  That did it thank you!!!
  19. Jonx
    Jonx avatar
    258 posts
    Member since:
    Jul 2012

    Posted 25 Nov 2010 Link to this post

    So cool. Exactly what I needed. It took me so long to fid it that I add it here for the record ;)

    "telerik Asp.net radgrid popup stay open after exception" :

    protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        try
        {
            GridEditableItem item = e.Item as GridEditableItem;
            Hashtable values = new Hashtable();
            item.ExtractValues(values);
            Session session = new Session();
            item.UpdateValues(session);
            DbContext.AddToSessions(session);
     
            //submit chanages to Db
            DbContext.SaveChanges();
        }
        catch (System.Exception)
        {
            e.Canceled = true; //keep the popup open
            ShowErrorMessage();
        }
    }

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017