This is a migrated thread and some comments may be shown as answers.

Rad Combo Box w/Checkboxes and Batch Grid

1 Answer 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Joel
Top achievements
Rank 1
Joel asked on 02 Sep 2014, 05:05 PM
Hello,

I've a grid with Batch Edit Mode enabled, In this grid I have a Template column that contains a RadComboBox with Checkboxes enabled, The issue is once the save changes button is cliked and the page posts back, I cannot find a way to get the Checked checkboxes collection. Im trying to achieve this by using BatchEditCommand method.

Is there anyway to achieve this??

My grid looks like this:

<telerik:RadGrid runat="server" ID="gv_ItemGrid" PageSize="50" Skin="Office2007" AllowSorting="true" AllowMultiRowSelection="true" AllowMultiRowEdit="true" AllowPaging="True" ShowGroupPanel="false" HeaderStyle-HorizontalAlign="Center" ClientSettings-AllowKeyboardNavigation="true" AutoGenerateColumns="false" AllowAutomaticDeletes="false" AllowAutomaticInserts="false" AllowAutomaticUpdates="false" OnNeedDataSource="gv_ItemGrid_NeedDataSource"  OnItemDataBound="gv_ItemGrid_ItemDataBound" OnBatchEditCommand="gv_ItemGrid_BatchEditCommand">
<PagerStyle Mode="NextPrevAndNumeric"/>
<ClientSettings AllowRowsDragDrop="False" AllowColumnsReorder="false" ReorderColumnsOnClient="false" EnableRowHoverStyle="true">
<Resizing AllowColumnResize="false" />
<Selecting AllowRowSelect="false" EnableDragToSelectRows="false"/>
<Scrolling AllowScroll="false" UseStaticHeaders="false"/>
<ClientEvents OnBatchEditOpening="batchEditOpening" OnBatchEditOpened="batchEditOpened" />
</ClientSettings>
<MasterTableView Name="gv_Items" CommandItemDisplay="Top" EditMode="Batch" DataKeyNames="PK">
<Columns>
<telerik:GridBoundColumn UniqueName="PK" DataField="PK" HeaderText="PK" Display="false"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="ItemCode" DataField="ItemCode" HeaderText="Item Code" SortExpression="ItemCode" HeaderStyle-Width="70px"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="Locations" DataField="Locations" HeaderText="Allocated to" HeaderStyle-Width="100px" Display="false"></telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="ItemDescription" HeaderText="Item Name" DataField="ItemDescription" HeaderStyle-Width="200px" ></telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="ManufactureDescription" HeaderText="Manufacture Description" DataField="ManufactureDescription" HeaderStyle-Width="100px" ></telerik:GridBoundColumn>
    <telerik:GridNumericColumn UniqueName="Cost" HeaderText="Cost" DataField="Cost" NumericType="Currency" DecimalDigits="2" AllowRounding="false" HeaderStyle-Width="60px" ></telerik:GridNumericColumn>
    <telerik:GridTemplateColumn UniqueName="CategoryIDs" HeaderText="Category Allocation" HeaderStyle-Width="300px" >
    <ItemTemplate>
        <asp:Label ID="lblCategoryLine" runat="server" Text='<%# Eval("CategoryIDs") %>' ></asp:Label>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadComboBox runat="server" EnableLoadOnDemand="true" ID="RadComboBox1" OnItemsRequested="RadComboBox1_ItemsRequested" DataTextField="LineCatDesc" DataValueField="seq" Skin="Office2007" MaxHeight="120px" Width="400px" CheckBoxes="true" EnableCheckAllItemsCheckBox="true"></telerik:RadComboBox>
    </EditItemTemplate>
        </telerik:GridTemplateColumn>
    <telerik:GridCheckBoxColumn UniqueName="active" HeaderText="Active" DataField="active" ItemStyle-HorizontalAlign="Center" HeaderStyle-Width="30px" ></telerik:GridCheckBoxColumn>
    <telerik:GridCheckBoxColumn UniqueName="isFilter" Display="false" HeaderText="Reports Filter" DataField="isFilter" ItemStyle-HorizontalAlign="Center"></telerik:GridCheckBoxColumn>
    <telerik:GridButtonColumn Visible="true" ConfirmText="Delete this Item?" ButtonType="ImageButton" CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
    <HeaderStyle Width="30px" />
    <ItemStyle HorizontalAlign="Center"/>
    </telerik:GridButtonColumn>
    </Columns>
        <CommandItemSettings ShowRefreshButton="false"  />
</MasterTableView>
</telerik:RadGrid>


and below my code behind scenes :D

protected void gv_ItemGrid_BatchEditCommand(object sender, GridBatchEditingEventArgs e)
        {
            foreach (GridBatchEditingCommand command in e.Commands)
            {
 
                if (command.Type == GridBatchEditingCommandType.Update)
                {
                    Hashtable newValues = command.NewValues;
                    Hashtable oldValues = command.OldValues;
                    RadComboBox ddlDesc = gv_ItemGrid.FindControl(gv_ItemGrid.MasterTableView.ClientID + "_CategoryIDs").FindControl("RadComboBox1") as RadComboBox;
 
                    string selectedValues = String.Empty;
                    if (ddlDesc.CheckBoxes) {
                        for (int i = 0; i < ddlDesc.CheckedItems.Count; i++)
                        {
                            selectedValues += (selectedValues == String.Empty)?(ddlDesc.CheckedItems[i] as RadComboBoxItem).Value:"," + (ddlDesc.CheckedItems[i] as RadComboBoxItem).Value;
                        }
                    }
 
                    for (int i = 0; i < ddlDesc.Items.Count; i++)
                    {
                        selectedValues += (selectedValues == String.Empty) ? ((ddlDesc.Items[i].Checked)?ddlDesc.Items[i].Value:string.Empty) : ((ddlDesc.Items[i].Checked)?"," + (ddlDesc.CheckedItems[i] as RadComboBoxItem).Value:string.Empty);
                        selectedValues += ddlDesc.Items[i].Checked.ToString();
                    }
                     
                    UBGlobal.SendEmail("Checkboxes Count", ddlDesc.Items.Count.ToString());
                }
 
                 
            }
 
        }


for statements are never happening since Item.checked and CheckedItems count is always Zero.

Any help would be greatly appreciated.

Thks in advance.

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 05 Sep 2014, 03:17 PM
Hello Joel,

I have to say that this scenario is not supported out of the box. In order to make things work one needs to handle things manually by subscribing to the four batch editing events(OnBatchEditGetCellValue, OnBatchEditSetCellValue, OnBatchEditGetEditorValueOnBatchEditSetEditorValue) as demonstrated here. The idea is to pass the checked combo items values to the arguments in the OnBatchEditGetEditorValue handler thus making them available on the server.

Give this suggestion a try and let us know if any problems arise.

Regards,
Angel Petrov
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.

 
Tags
Grid
Asked by
Joel
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or