RadGrid batch edit mode issues.

19 posts, 1 answers
  1. Will
    Will avatar
    16 posts
    Member since:
    Aug 2013

    Posted 31 Jan 2014 Link to this post

    Usually it works fine When I used the batch edit mode in the radgird.
    Occasionally,it can't work , you can see the errors in pictures below.
    It shows that the count of command items in the e.Commands is zero and ,in the grid, the updated cell marked a red small triangle on the top right.
    I can't figure out why there is no item in the e.Commands.
    Thanks in advance.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 31 Jan 2014 in reply to Will Link to this post

    Hi Will,

    I'm not able to replicate the issue at my end. Here is a sample that i tried, have a look. If this doesn't help, please provide your full code snippet :

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="false" OnNeedDataSource="RadGrid1_NeedDataSource" OnBatchEditCommand="RadGrid1_BatchEditCommand" AutoGenerateColumns="false">
        <MasterTableView EditMode="Batch" CommandItemDisplay="Top" DataKeyNames="OrderID">
            <BatchEditingSettings OpenEditingEvent="Click" EditType="Cell" />
            <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" ReadOnly="true" />
            <telerik:GridBoundColumn DataField="ShipName" HeaderText="ShipName" UniqueName="ShipName" />
            </Columns>
        </MasterTableView
    </telerik:RadGrid>

    C#:
    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
     foreach (GridBatchEditingCommand command in e.Commands)
      {
        if ((command.Type == GridBatchEditingCommandType.Update))
        {
         Hashtable newValues = command.NewValues;
         Hashtable oldValues = command.OldValues;
         string OrderID = newValues["OrderID"].ToString();
         string ShipName = newValues["ShipName"].ToString();      
        }
      }
    }

    Thanks,
    Princy

  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Will
    Will avatar
    16 posts
    Member since:
    Aug 2013

    Posted 03 Feb 2014 Link to this post

    Hi Princy,
    I'm glad to see your reply. I pasted the code below which removed some unnecessary read-only columns.
    In the grid, there is a master table view and a detail table view. the columns in the two view are almost the same. Master table represents the data within a day and the detail table shows the data of an OrderID.I hope you could understand what I'm saying.
    And the strangest is I can update the data in the detail table view which I can't in the master view.The most operations are done in the master view.

    <telerik:RadGrid ID="RadGrid1" runat="server" LoadingPanelID="RadAjaxLoadingPanel1"
            CellSpacing="0" GridLines="None" ShowStatusBar="True"
            onneeddatasource="RadGrid1_NeedDataSource" ondetailtabledatabind="RadGrid1_DetailTableDataBind"
        AutoGenerateColumns="False" onbatcheditcommand="RadGrid1_BatchEditCommand" Skin="Metro" Width="2000px" >
                    <MasterTableView CommandItemDisplay="TopAndBottom"
                        DataKeyNames="Id,OrderId,SourceAreaId" EditMode="Batch">
                        <DetailTables>
                            <telerik:GridTableView runat="server" CommandItemDisplay="Bottom"
                                DataKeyNames="Id" EditMode="Batch" meta:resourcekey="GridTableViewResource1"
                                Name="OrderDetailsOfArea">
                                <CommandItemSettings ExportToPdfText="Export to PDF"
                                    ShowAddNewRecordButton="False" />
                                <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
                                    Visible="True">
                                    <HeaderStyle Width="20px" />
                                </RowIndicatorColumn>
                                <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
                                    Visible="True">
                                    <HeaderStyle Width="20px" />
                                </ExpandCollapseColumn>
                                <Columns>
     
                                    <telerik:GridTemplateColumn DataField="TourLeaderName"
                                FilterControlAltText="Filter TourLeaderName column" HeaderText="Tour Leader"
                                SortExpression="TourLeaderName" UniqueName="TourLeaderName">
                                <EditItemTemplate>
                                    <asp:Label ID="LabelTourLeaderName" runat="server"
                                        Text='<%# Eval("TourLeaderName")%>' ToolTip='<%# Eval("TourLeaderMobile") %>'></asp:Label>
                                    <br />
                                    <%# Eval("TourLeaderMobile")%>                           
                                </EditItemTemplate>
                                <ItemTemplate>
     
                                    <asp:Label ID="LabelTourLeaderName" runat="server"
                                        Text='<%# Eval("TourLeaderName")%>' ToolTip='<%# Eval("TourLeaderMobile") %>'></asp:Label>
                                    <br />
                                    <%# Eval("TourLeaderMobile")%>          
                                </ItemTemplate>
                                <HeaderStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            </telerik:GridTemplateColumn>
     
     
                                    <telerik:GridTemplateColumn DataField="CoachIdNumber"
                                        FilterControlAltText="Filter CoachIdNumber column" HeaderText="Coach"
                                        SortExpression="CoachIdNumber" UniqueName="CoachIdNumber">
                                        <ItemTemplate>
                                            <asp:Label ID="CoachIdNumberLabel" runat="server"
                                                Text='<%# Eval("CoachIdNumber")%>'></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadComboBox ID="CoachDropDownD" runat="server"
                                                DataSourceID="SqlDataSourceCoach" DataTextField="CoachIdNumber"
                                                DataValueField="Id" Filter="StartsWith" Width="100px">
                                            </telerik:RadComboBox>
                                            <input id="ButtonClearCoachIdNumberDetail" type="button" value="Clear" onclick="ClearSelection('CoachDropDownD')" />
                                        </EditItemTemplate>
                                        <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                            ForeColor="Red" Width="120px" />
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn DataField="DriverAliasName"
                                        FilterControlAltText="Filter DriverAliasName column" HeaderText="DRIVER"
                                        SortExpression="DriverAliasName" UniqueName="DriverAliasName">
                                        <ItemTemplate>
                                            <asp:Label ID="DriverAliasNameLabel" runat="server"
                                                Text='<%# Eval("DriverAliasName")%>' ToolTip='<%# Eval("DriverPhoneNumber") %>'></asp:Label>
                                            <br />
                                            <%# Eval("DriverPhoneNumber") %>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadComboBox ID="DriverDropDownD" runat="server"
                                                DataSourceID="SqlDataSourceDriver" DataTextField="AliasName"
                                                DataValueField="Id" Filter="StartsWith" Width="100px">
                                            </telerik:RadComboBox>
                                            <input id="ButtonClearDriverAliasNameDetail" type="button" value="Clear" onclick="ClearSelection('DriverDropDownD')" />
                                        </EditItemTemplate>
                                        <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                            ForeColor="Red" Width="120px" />
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridTemplateColumn DataField="TrailerId"
                                        FilterControlAltText="Filter TrailerIdNumber column" HeaderText="Trailer"
                                        SortExpression="TrailerIdNumber" UniqueName="TrailerIdNumber">
                                        <ItemTemplate>
                                            <asp:Label ID="TrailerIdNumberLabel" runat="server"
                                                Text='<%# Eval("TrailerIdNumber")%>'></asp:Label>
                                        </ItemTemplate>
                                        <EditItemTemplate>
                                            <telerik:RadComboBox ID="TrailerDropDownD" runat="server"
                                                DataSourceID="SqlDataSourceTrailer" DataTextField="TrailerIdNumber"
                                                DataValueField="Id" Filter="StartsWith" ViewStateMode="Enabled" Width="80px">
                                            </telerik:RadComboBox>
                                            <input id="ButtonClearTrailerDetail" type="button" value="Clear" onclick="ClearSelection('TrailerDropDownD')" />
                                        </EditItemTemplate>
                                        <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                            ForeColor="Red" Width="100px" />
                                    </telerik:GridTemplateColumn>
                                    <telerik:GridCheckBoxColumn DataField="ManagerNotifyDriver"
                                        DataType="System.Boolean"
                                        FilterControlAltText="Filter ManagerNotifyDriver column" HeaderText="Fax"
                                        SortExpression="ManagerNotifyDriver" UniqueName="ManagerNotifyDriver">
                                        <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                            ForeColor="Red" Width="60px" />
                                    </telerik:GridCheckBoxColumn>
                                     
                                </Columns>
                                <EditFormSettings>
                                    <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                                    </EditColumn>
                                </EditFormSettings>
                                <BatchEditingSettings EditType="Cell" />
                                <PagerStyle PageSizeControlType="RadComboBox" />
                            </telerik:GridTableView>
                        </DetailTables>
                        <CommandItemSettings ExportToPdfText="Export to PDF"
                            ShowAddNewRecordButton="False" />
                        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column"
                            Visible="True">
                            <HeaderStyle Width="20px" />
                        </RowIndicatorColumn>
                        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column"
                            Visible="True">
                            <HeaderStyle Width="20px" />
                        </ExpandCollapseColumn>
                        <EditFormSettings>
                            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
                            </EditColumn>
                        </EditFormSettings>
                        <BatchEditingSettings EditType="Cell" />
                        <PagerStyle PageSizeControlType="RadComboBox" />
                        <Columns>
                             
     
                            <telerik:GridTemplateColumn DataField="TourLeaderName"
                                FilterControlAltText="Filter TourLeaderName column" HeaderText="Tour Leader"
                                SortExpression="TourLeaderName" UniqueName="TourLeaderName">
                                <EditItemTemplate>
                                    <asp:Label ID="LabelTourLeaderName" runat="server"
                                        Text='<%# Eval("TourLeaderName")%>' ToolTip='<%# Eval("TourLeaderMobile") %>'></asp:Label>
                                    <br />
                                    <%# Eval("TourLeaderMobile")%>                           
                                </EditItemTemplate>
                                <ItemTemplate>
     
                                    <asp:Label ID="LabelTourLeaderName" runat="server"
                                        Text='<%# Eval("TourLeaderName")%>' ToolTip='<%# Eval("TourLeaderMobile") %>'></asp:Label>
                                    <br />
                                    <%# Eval("TourLeaderMobile")%>          
                                </ItemTemplate>
                                <HeaderStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                            </telerik:GridTemplateColumn>
     
     
                            <telerik:GridTemplateColumn DataField="HotelName"
                                FilterControlAltText="Filter HotelName column" HeaderText="Hotel"
                                SortExpression="HotelName" UniqueName="HotelName">
                                <EditItemTemplate>
                                    <asp:Label ID="HotelNameLabel" runat="server" ToolTip='<%# Eval("HotelAddress") %>' Text='<%# Eval("HotelName") %>'></asp:Label>
                                </EditItemTemplate>
                                <ItemTemplate>
                                    <asp:Label ID="HotelNameLabel" runat="server" ToolTip='<%# Eval("HotelAddress") %>' Text='<%# Eval("HotelName") %>'></asp:Label>
                                </ItemTemplate>
                            </telerik:GridTemplateColumn>
     
     
     
                            <telerik:GridTemplateColumn DataField="CoachIdNumber"
                                FilterControlAltText="Filter CoachIdNumber column" HeaderText="Coach"
                                SortExpression="CoachIdNumber" UniqueName="CoachIdNumber">
                                <ItemTemplate>
                                    <asp:Label ID="CoachIdNumberLabel" runat="server"
                                        Text='<%# Eval("CoachIdNumber")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="CoachDropDownM" Runat="server" HighlightTemplatedItems="true"
                                        DataSourceID="SqlDataSourceCoach" DataTextField="CoachIdNumber" DataValueField="Id"
                                        Filter="StartsWith" ExpandDelay="0" MaxHeight="200px" Width="140px">
                                            <HeaderTemplate>
                                                <ul>
                                                     <li class="col1n">Coach</li>
                                                     <li class="col2n">Size</li>
                                                </ul>
                                           </HeaderTemplate>
                                           <ItemTemplate>
                                                <ul>
                                                     <li class="col1n" title='<%# DataBinder.Eval(Container.DataItem, "CoachIdNumber")%>'>
                                                          <%# DataBinder.Eval(Container.DataItem, "CoachIdNumber")%></li>
                                                     <li class="col2n">
                                                          <%# DataBinder.Eval(Container.DataItem, "Size")%></li>
                                                </ul>
                                           </ItemTemplate>
                                    </telerik:RadComboBox>
     
                                    <input id="ButtonClearCoachIdNumberMaster" type="button" value="Clear" onclick="ClearSelection('CoachDropDownM')" />
                                </EditItemTemplate>
                                <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                    ForeColor="Red" Width="160px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="DriverAliasName"
                                FilterControlAltText="Filter DriverAliasName column" HeaderText="DRIVER"
                                SortExpression="DriverAliasName" UniqueName="DriverAliasName">
                                <ItemTemplate>
                                    <asp:Label ID="DriverAliasNameLabel" runat="server"
                                        Text='<%# Eval("DriverAliasName")%>' ToolTip='<%# Eval("DriverPhoneNumber") %>'></asp:Label>
                                    <br />
                                    <%# Eval("DriverPhoneNumber") %>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="DriverDropDownM" runat="server"
                                        DataSourceID="SqlDataSourceDriver" DataTextField="AliasName"
                                        DataValueField="Id" Filter="StartsWith" Width="100px">
                                    </telerik:RadComboBox>
                                    <input id="ButtonClearDriverAliasNameMaster" type="button" value="Clear" onclick="ClearSelection('DriverDropDownM')" />
                                </EditItemTemplate>
                                <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                    ForeColor="Red" Width="120px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridTemplateColumn DataField="TrailerId"
                                FilterControlAltText="Filter TrailerIdNumber column" HeaderText="Trailer"
                                SortExpression="TrailerIdNumber" UniqueName="TrailerIdNumber">
                                <ItemTemplate>
                                    <asp:Label ID="TrailerIdNumberLabel" runat="server"
                                        Text='<%# Eval("TrailerIdNumber")%>'></asp:Label>
                                </ItemTemplate>
                                <EditItemTemplate>
                                    <telerik:RadComboBox ID="TrailerDropDownM" runat="server"
                                        DataSourceID="SqlDataSourceTrailer" DataTextField="TrailerIdNumber"
                                        DataValueField="Id" Filter="StartsWith" ViewStateMode="Enabled" Width="70px">
                                    </telerik:RadComboBox>
                                    <input id="ButtonClearTrailerMaster" type="button" value="Clear" onclick="ClearSelection('TrailerDropDownM')" />
                                </EditItemTemplate>
                                <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                    ForeColor="Red" Width="80px" />
                            </telerik:GridTemplateColumn>
                            <telerik:GridCheckBoxColumn DataField="ManagerNotifyDriver"
                                DataType="System.Boolean"
                                FilterControlAltText="Filter ManagerNotifyDriver column" HeaderText="F"
                                SortExpression="ManagerNotifyDriver" UniqueName="ManagerNotifyDriver">
                                <HeaderStyle Font-Bold="true" Font-Italic="true" Font-Size="Large"
                                    ForeColor="Red" Width="30px" />
                            </telerik:GridCheckBoxColumn>
     
     
                            <telerik:GridBoundColumn DataField="SubmitDate" DataType="System.DateTime"
                                FilterControlAltText="Filter SubmitDate column" HeaderText="SUB DATE"
                                ReadOnly="true" SortExpression="SubmitDate" UniqueName="SubmitDate">
                                <HeaderStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" />
                            </telerik:GridBoundColumn>
                        </Columns>
                        <CommandItemStyle Font-Bold="True" Font-Italic="True" HorizontalAlign="Right"
                            VerticalAlign="Middle" Width="100%" />
                    </MasterTableView>
                    <CommandItemStyle CssClass="Content2" HorizontalAlign="Center"
                        VerticalAlign="Middle" Width="100%" />
     
    <PagerStyle PageSizeControlType="RadComboBox"></PagerStyle>
     
    <FilterMenu EnableImageSprites="False"></FilterMenu>
    </telerik:RadGrid>

    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
     
        if (e.Item.OwnerTableView.Name == "OrderDetailsOfArea")
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                if (command.Type == GridBatchEditingCommandType.Update)
                {
                    try
                    {
                        Hashtable newValues = command.NewValues;
     
                        OrderAppService service = new OrderAppService();
     
                        service.UpdateOrderDetailArrangement(OrderDtoFactory.ExtractValuesFromItem2(newValues), new Guid(Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString()));
                    }
                    catch (Exception ex)
                    {
                        //SetMessage("Reason: " + ex.Message);
                    }
                }
            }
        }
        else if (e.Item.OwnerTableView.Name == "")
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                if (command.Type == GridBatchEditingCommandType.Update)
                {
                    try
                    {
                        Hashtable newValues = command.NewValues;
     
                        OrderAppService service = new OrderAppService();
     
                        service.UpdateOrderDetailArrangement(OrderDtoFactory.ExtractValuesFromItem2(newValues), new Guid(Membership.GetUser(HttpContext.Current.User.Identity.Name).ProviderUserKey.ToString()));
                    }
                    catch (Exception ex)
                    {
                        //SetMessage("Reason: " + ex.Message);
                    }
                }
            }
        }
    }
  5. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 03 Feb 2014 in reply to Will Link to this post

    Hi Will,

    Unfortunately, I couldn't replicate the issue at my end. Below is the sample code snippet that i tried:

    ASPX:
    <telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="true" OnNeedDataSource="RadGrid1_NeedDataSource"
        OnDetailTableDataBind="RadGrid1_DetailTableDataBind" AutoGenerateColumns="False"
        OnBatchEditCommand="RadGrid1_BatchEditCommand" Skin="Metro">
        <MasterTableView CommandItemDisplay="TopAndBottom" DataKeyNames="CustomerID" EditMode="Batch"
            BatchEditingSettings-OpenEditingEvent="Click">
            <BatchEditingSettings EditType="Cell" />
            <DetailTables>
                <telerik:GridTableView runat="server" CommandItemDisplay="Bottom" DataKeyNames="OrderID"
                    EditMode="Batch" Name="Orders">
                    <Columns>
                        <telerik:GridTemplateColumn DataField="OrderID" HeaderText="OrderID" UniqueName="OrderID">
                            <EditItemTemplate>
                                <asp:TextBox ID="TextBox1" runat="server" Text='<%# Eval("OrderID")%>'></asp:TextBox>
                            </EditItemTemplate>
                            <ItemTemplate>
                                <%# Eval("OrderID")%>
                            </ItemTemplate>
                            <HeaderStyle Font-Bold="True" HorizontalAlign="Center" VerticalAlign="Middle" Width="100px" />
                        </telerik:GridTemplateColumn>
                        <telerik:GridTemplateColumn DataField="ShipName" HeaderText="ShipName" UniqueName="ShipName">
                            <ItemTemplate>
                                <%# Eval("ShipName")%>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox ID="RadComboShipName" runat="server" DataSourceID="SqlDataSource1"
                                    DataTextField="ShipName" DataValueField="OrderID" Filter="StartsWith">
                                </telerik:RadComboBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                    <BatchEditingSettings EditType="Cell" />
                    <PagerStyle PageSizeControlType="RadComboBox" />
                </telerik:GridTableView>
            </DetailTables>
            <Columns>
                <telerik:GridTemplateColumn DataField="CustomerID" FilterControlAltText="Filter CustomerID column"
                    HeaderText="CustomerID" SortExpression="CustomerID" UniqueName="CustomerID">
                    <EditItemTemplate>
                        <asp:TextBox ID="TextBox2" runat="server" Text='<%# Eval("CustomerID")%>'></asp:TextBox>
                    </EditItemTemplate>
                    <ItemTemplate>
                        <%# Eval("CustomerID")%>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn DataField="ContactName" HeaderText="ContactName" UniqueName="ContactName">
                    <ItemTemplate>
                        <asp:Label ID="ContactNameLabel" runat="server" Text='<%# Eval("ContactName")%>'></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox ID="ContactNameDropDownM" runat="server" HighlightTemplatedItems="true"
                            DataSourceID="SqlDataSource2" DataTextField="ContactName" DataValueField="CustomerID"
                            Filter="StartsWith" ExpandDelay="0" MaxHeight="200px" Width="140px">
                            <HeaderTemplate>
                                <ul>
                                    <li class="col1n">ContactName</li>
                                    <li class="col2n">ID</li>
                                </ul>
                            </HeaderTemplate>
                            <ItemTemplate>
                                <ul>
                                    <li class="col1n" title='<%# DataBinder.Eval(Container.DataItem, "ContactName")%>'>
                                        <%# DataBinder.Eval(Container.DataItem, "ContactName")%></li>
                                    <li class="col2n">
                                        <%# DataBinder.Eval(Container.DataItem, "CustomerID")%></li>
                                </ul>
                            </ItemTemplate>
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
        </MasterTableView>
    </telerik:RadGrid>

    C#:
    protected void RadGrid1_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)
    {
        if (!e.IsFromDetailTable)
        {
            RadGrid1.DataSource = GetDataTable("SELECT * FROM Customers");
        }
    }
     
    protected void RadGrid1_DetailTableDataBind(object source, Telerik.Web.UI.GridDetailTableDataBindEventArgs e)
    {
        GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
        switch (e.DetailTableView.Name)
        {
            case "Orders":
                {
                    string CustomerID = dataItem.GetDataKeyValue("CustomerID").ToString();
                    e.DetailTableView.DataSource = GetDataTable("SELECT * FROM Orders WHERE CustomerID = '" + CustomerID + "'");
                    break;
                }
        }
    }
     
    public DataTable GetDataTable(string query)
    {
        String ConnString = ConfigurationManager.ConnectionStrings["Northwind_newConnectionString3"].ConnectionString;
        SqlConnection conn = new SqlConnection(ConnString);
        SqlDataAdapter adapter = new SqlDataAdapter();
        adapter.SelectCommand = new SqlCommand(query, conn);
     
        DataTable myDataTable = new DataTable();
     
        conn.Open();
        try
        {
            adapter.Fill(myDataTable);
        }
        finally
        {
            conn.Close();
        }
     
        return myDataTable;
    }
     
    protected void RadGrid1_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
    {
     
        if (e.Item.OwnerTableView.Name == "Orders")
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                if (command.Type == GridBatchEditingCommandType.Update)
                {
                    try
                    {
                        Hashtable newValues = command.NewValues;
                    }
                    catch (Exception ex)
                    {
                        //SetMessage("Reason: " + ex.Message);
                    }
                }
            }
        }
        else if (e.Item.OwnerTableView.Name == "")
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
                if (command.Type == GridBatchEditingCommandType.Update)
                {
                    try
                    {
                        Hashtable newValues = command.NewValues;
                    }
                    catch (Exception ex)
                    {
                        //SetMessage("Reason: " + ex.Message);
                    }
                }
            }
        }
    }

    Thanks,
    Princy
  6. Preeti
    Preeti avatar
    8 posts
    Member since:
    Jan 2014

    Posted 04 Feb 2014 in reply to Princy Link to this post

    Hi Princy,



    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx


    I
    want to implement the grid check box which is used in above link but
    there is a problem of datatype of that discontinued coloumn..please tell
    me which data type is used when a boolean value is passed?
  7. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 04 Feb 2014 in reply to Preeti Link to this post

    Hi Preeti,

    GridCheckBoxColumn displays a check box to represent a Boolean value. Bind this column type to a Boolean field by setting its DataField property. If this column type is bound to a data value that is not Boolean, the grid throws an exception.
    When the grid is in browser mode, or if the column is read-only, the check box is disabled. When the column is editable, the check box is enabled.

    Thanks,
    Princy
  8. Mujeeb
    Mujeeb avatar
    6 posts
    Member since:
    May 2014

    Posted 03 May 2014 Link to this post

    Hi Telerik Team,

    I have an issue.

    I had used the batch editing radgrid sample
    http://demos.telerik.com/aspnet-ajax/grid/examples/data-editing/batch-editing/defaultcs.aspx

    and the multicolumn radcombobox avialable in the url
    http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/comboingrid/defaultcs.aspx?product=grid#qsf-demo-source

    in the batch edit. But when I select any of the values from the combo the selected item is to maintaining in the grid.

    Please help me to solve this issue.
  9. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 07 May 2014 Link to this post

    Hello Mujeeb,

    If you are using the same settings for the RadComboBox as in the online demo that you are referring to, you should have in mind that if the AutoPostBack property of the control is set to true, once an item is selected, a postback will occur and the changes will not be applied. In order to get the RadComboBox to work with Batch edit mode you will have to set the AutoPostBack to false (its default value).

    Attached you could find is a simple example demonstrating how to implement the RadComboBox from the demo with Batch edit mode:

    Hope that helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  10. Mujeeb
    Mujeeb avatar
    6 posts
    Member since:
    May 2014

    Posted 07 May 2014 in reply to Konstantin Dikov Link to this post

    Thank You Konstantin Dikov for the code sample.

    I also need the code sample to insert / update the items from code behind by using the Enter Key event.

    Can you help me with a code sample Please?

    Thank You
    Mujeeb
  11. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 08 May 2014 Link to this post

    Hello Mujeeb,

    If you want to save the changes within a RadGrid using Batch edit mode when the Enter key is pressed, you could handle the client-side OnKeyPress event of the grid and if the Enter key is pressed, get reference to the BatchEditingManager and fire the saveAllChanges() method:
    <telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function keyPress(sender, args) {
                if (args.get_keyCode() == 13) {
                    sender.get_batchEditingManager().saveAllChanges();
                }
            }
        </script>
    </telerik:RadCodeBlock>
     
    <telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
        <MasterTableView EditMode="Batch">
        </MasterTableView>
        <ClientSettings>
            <ClientEvents OnKeyPress="keyPress" />
        </ClientSettings>
    </telerik:RadGrid>

    Nevertheless, the above scenario defeats the purpose of Batch edit mode if you are going to save the changes each time the Enter key is pressed. The main idea of Batch edit mode is to manipulate the data on client-side and save the changes once you are done.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  12. Mujeeb
    Mujeeb avatar
    6 posts
    Member since:
    May 2014

    Posted 08 May 2014 in reply to Konstantin Dikov Link to this post

    Hi Konstantin Dikov,

    Can I have a code for inserting the values through code behind in batch edit mode.

    Thank You and Kind Regards
    Mujeeb

  13. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 09 May 2014 Link to this post

    Hello Mujeeb,

    I am not sure if I understand your requirement and what you want to achieve. 

    When Batch edit mode is used, inserting items is possible only on client-side. If you want to add items from the code-behind, what you could do is to add those items to the data source, before assigning it to the grid.

    Another possible solution would be to insert records to your database directly and then force the grid to rebind, so it could retrieve the new data.

    Hope that helps.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  14. Will
    Will avatar
    16 posts
    Member since:
    Aug 2013

    Posted 16 Jul 2014 Link to this post

    hi everyone, I found something new.

    Error messages are below.

    There is something wrong with the method "substring" which is not in my code.

    I'm not sure whether it is a bug of Radcontrol.

    I hope someone could help me. Thanks in advance.
    Server Error in '/Jubo' Application.
     
    Length cannot be less than zero.
    Parameter name: length
     
    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.ArgumentOutOfRangeException: Length cannot be less than zero.
    Parameter name: length
     
    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:
     
     
    [ArgumentOutOfRangeException: Length cannot be less than zero.
    Parameter name: length]
       System.String.Substring(Int32 startIndex, Int32 length) +10993435
       Telerik.Web.UI.GridBatchEditingCommand..ctor(GridTableView ownerTableView, DataSourceView dataSourceView, String command) +81
       Telerik.Web.UI.GridBatchEditingEventArgs.CreateCommands() +221
       Jubo.Presentation.Web.OrderManagement.OrderArrangementU.RadGrid1_BatchEditCommand(Object sender, GridBatchEditingEventArgs e) in D:\_WorkSpace\Jubo\JuboLight\Jubo.Presentation.Web\OrderManagement\OrderArrangementU.aspx.cs:133
       Telerik.Web.UI.RadGrid.OnBatchEditCommand(GridBatchEditingEventArgs e) +91
       Telerik.Web.UI.GridBatchEditingEventArgs.ExecuteCommand(Object source) +51
       Telerik.Web.UI.RadGrid.RaisePostBackEvent(String eventArgument) +2769
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +9703566
       System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
     
    Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34009
  15. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 18 Jul 2014 Link to this post

    Hello Will,

    Since the error that you are describing is rather unexpected, could you please elaborate on your exact scenario, when you are receiving that error and which version of our controls you are using.

    Finally, are you receiving the error when entering any special characters or the error occurs no matter what is entered.

    I am looking forward to your reply.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  16. Will
    Will avatar
    16 posts
    Member since:
    Aug 2013

    Posted 18 Jul 2014 in reply to Konstantin Dikov Link to this post

    Hello Konstantin,
    I've found out the cause of the problem.
    You're right,  the error occured when there is the character "&" in the cell of the row even if the cell is readonly.

    Regards,
    Will New
  17. Answer
    Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 22 Jul 2014 Link to this post

    Hello Will,

    Thank you for the information.

    Actually, there was indeed such issue with special characters with previous versions of our controls, but I am really glad to say that this bug is now fixed. You could take a look at the item created in our Ideas & Feedback Portal regarding the issue with special characters:
    Could you please upgrade to our latest version and see if everything is working correctly with it.


    Regards,
    Konstantin Dikov
    Telerik
     

    Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

     
  18. Stefhan
    Stefhan avatar
    3 posts
    Member since:
    May 2015

    Posted 29 May 2015 Link to this post

    Hi.

    We also want users to be able to save changes to rows by pressing the Enter key. We have tried using the suggested code:

     

    $(document).keypress(function(e) {
        if(e.which == 13) {
            sender.get_batchEditingManager().saveAllChanges();
        }
    });

    The function is fired, but the changes aren't saved. Then for testing purposes we set the keypress event for the entire page like this:

     

    function keyPress(sender, args) {
                if (args.get_keyCode() == 13) {
                    sender.get_batchEditingManager().saveAllChanges();
                }
            };

    Now if we edit a row, then click somewhere outside the radgrid (so the input for edit is "closed" / "looses focus") and then press Enter, the changes are saved. So it seems that we have to somehow in the keypress event say "close edit input" --> "save changes." How can we achieve this?

     

    Best regards,

     
    Stefhan.

  19. Stefhan
    Stefhan avatar
    3 posts
    Member since:
    May 2015

    Posted 29 May 2015 in reply to Stefhan Link to this post

    The two code snippets should switch places. :)
  20. Konstantin Dikov
    Admin
    Konstantin Dikov avatar
    1795 posts

    Posted 02 Jun 2015 Link to this post

    Hi Stefhan,

    You can use the BatchEditingManager _tryCloseEdits(tableView) method in order to close currently edited cell/row:
    <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
        <script type="text/javascript">
            function pageLoad() {
                $(document).keypress(function (e) {
                    if (e.which == 13) {
                        preventEvent(e)
                        var grid = $find("<%=RadGrid1.ClientID%>");
                        var batchManager = grid.get_batchEditingManager();
                        batchManager._tryCloseEdits(grid.get_masterTableView());
                        batchManager.saveAllChanges();
                    }
                });
            }
     
            function preventEvent(e) {
                var evt = e ? e : window.event;
                if (evt.stopPropagation) evt.stopPropagation();
                if (evt.preventDefault) evt.preventDefault();
                if (evt.cancelBubble != null) evt.cancelBubble = true;
                if (evt.stopImmediatePropagation) evt.stopImmediatePropagation();
                evt.returnValue = false;
            }
        </script>
    </telerik:RadCodeBlock>

    Please note that we are also preventing the Enter key from submitting the form.


    Regards,
    Konstantin Dikov
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for ASP.NET Ajax is Ready for VS 2017