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

Read attribute value of combo inside RadGrid

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
anil
Top achievements
Rank 1
anil asked on 19 Nov 2014, 02:46 PM

I am creating one entry screen using RadGrid in Batch Edit Mode. My Grid is having mainly some columns of ComboBox (rdcombPayCodeNm) and  TextBox ("txtHours" or "txtAmount"). I have added attribute like "PaidInAmount"/"PaidInHours" in RadCombo in PageLoad.  I want to verify textBox value based on user selected item and their attribut value of ComboBox. Suppose user selected one item in combo and their attribute value is  "PaidInAmount" then user should not enter any value in "txtHours" textbox and opposite if user selected combobox attribute is "PaidInHours" then there should be any value in "txtAmount" textbox. There would be multiple row in grid and I have to validate one by one row and show message to user. I want to perform this operation in client side as I can't read grid value in server side in BatchEdit mode.

I am copying my aspx code and code behind for your ref.

ASPX
------------------------------------------------------------------
<telerik:RadGrid ID="rdgvOtherPay" runat="server" AllowAutomaticInserts="True" AllowAutomaticUpdates="true" AllowMultiRowEdit="true" AllowPaging="True"
    AutoGenerateColumns="False" CellSpacing="0" OnNeedDataSource="rdgvOtherPay_NeedDataSource"
    GridLines="None"
    PageSize="12" AllowMultiRowSelection="true">
    <ClientSettings>
        <ClientEvents OnBatchEditSetEditorValue="setEditorValue" OnRowCreated="rowCreated" OnBatchEditOpened="editOpened" />
    </ClientSettings>
    <MasterTableView AutoGenerateColumns="False" CommandItemDisplay="Top" CommandItemSettings-AddNewRecordText=""
        CommandItemSettings-CancelChangesText="" CommandItemSettings-RefreshText="" CommandItemSettings-ShowRefreshButton="false"
        CommandItemSettings-ShowSaveChangesButton="false" CommandItemSettings-ShowCancelChangesButton="false" DataKeyNames="idEmpOtherPay"
        Dir="rtl" EditMode="Batch" HorizontalAlign="NotSet" InsertItemDisplay="Bottom">
        <BatchEditingSettings EditType="Row" />
        <SortExpressions>
            <telerik:GridSortExpression FieldName="idEmpOtherPay" SortOrder="Descending" />
        </SortExpressions>
        <Columns>
            
            <telerik:GridTemplateColumn DataField="PayCodeId" HeaderStyle-Width="110px" HeaderText="Pay Code" UniqueName="PayCodeId">
                <ItemTemplate>
                    <%# Eval("PayCodeName") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadComboBox ID="rdcombPayCodeNm" runat="server" class="TelerikDrop" dir="ltr" DropDownAutoWidth="Enabled" Filter="StartsWith" TabIndex="8"
                         >
                        <Items>
                            <telerik:RadComboBoxItem Text="PayCodeName1" />
                            <telerik:RadComboBoxItem Text="PayCodeName2" />
                        </Items>
                    </telerik:RadComboBox>
                    <span style="color: red; font-size: larger; vertical-align: bottom">
                    </span>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridTemplateColumn DataField="OtherHours" HeaderStyle-Width="90px" HeaderText="Hours" UniqueName="OtherHours">
                <ItemTemplate>
                    <asp:Label runat="server" ID="lblOtherHours" Text='<%# Eval("OtherHours") %>'></asp:Label>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadNumericTextBox ID="txtHours" runat="server" MaxLength="15" Width="80%">
                        <NumberFormat DecimalDigits="2" GroupSeparator="" />
                    </telerik:RadNumericTextBox>
                    <%--<ajax:popupcontrolextender id="PopupControlExtender1" runat="server" popupcontrolid="Panel1" position="Bottom" targetcontrolid="txtHours" />--%>
                    <span style="color: red; font-size: larger; vertical-align: bottom">
                    </span>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            
            <telerik:GridTemplateColumn DataField="OtherAmount" HeaderStyle-Width="90px" HeaderText="Amount" UniqueName="OtherAmount">
                <ItemTemplate>
                    <%# Convert.ToDouble(Eval("OtherAmount")).ToString("0.00") %>
                </ItemTemplate>
                <EditItemTemplate>
                    <telerik:RadNumericTextBox ID="txtAmount" runat="server" MaxLength="15" Width="80%">
                        <NumberFormat DecimalDigits="2" GroupSeparator="" />
                    </telerik:RadNumericTextBox>
                    <span style="color: red; font-size: larger; vertical-align: bottom"></span>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridButtonColumn ConfirmText="Delete Other Earnings?" ConfirmDialogType="RadWindow"
                ConfirmTitle="Delete" HeaderText="Delete" HeaderStyle-Width="50px" ButtonType="ImageButton"
                CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
            </telerik:GridButtonColumn>
        </Columns>
        <PagerStyle Mode="NumericPages" ShowPagerText="False" />
    </MasterTableView>
</telerik:RadGrid>



Code Behind-


            foreach (PayCodeDO _row in payCodeList)
            {
                RadComboBoxItem item = new RadComboBoxItem
                {
                    Value = _row.PayCodeId.ToString() + " " + _row.Description,
                    Text = _row.Description,
                };
                // string noOfHours = Convert.ToString(_row.PaidInAmount);
                item.Attributes.Add("PaidInAmount", _row.PaidInAmount);
                item.Attributes.Add("PaidInHours", _row.PaidInHours);
                item.Attributes.Add("PaidInHrAndAm", _row.PaidInHourseAndAmount);
                payCodeCombo.Items.Add(item);
            }

            payCodeCombo.Items.Insert(0, new RadComboBoxItem(""));



Thank in Advance.

Regards,
Anil

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 24 Nov 2014, 12:14 PM
Hi Anil,

If I correctly understand the requirement you want to disable/enable certain editors according to the attributes of the selected combo item. If that is the case you can achieve the desired goal by following the steps listed below.
  1. Subscribe to the OnBatchEditOpened event(like you have already done).
  2. When the last cell of the row is opened obtain a reference to the selected item of the combo and check its attributes.
  3. Based on the results of the above point disable/enable the editors inside the row.

Additionally note that you should also disable/enabled the editors once the combo selection is changed. For that purpose you can subscribe to the OnSelectedIndexChanged event.

In attachment you can find a sample website that illustrates a possible realization of the described scenario. Please examine its implementation and let us know if this is what you were looking for.


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
anil
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or