Click here to Skip to main content
15,940,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am using Telerik Grid. Now I want that if the radio button of the row is checked then only I should be able to Edit that Row. Else on clicking the edit button of unchecked row should show "Please select this Row first".

How could I accomplish this using Java script or any other way? Please help me. Below is script I have used to allow allow only one radio button Selection. It is working fine.
ASP.NET
<telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
    <script type="text/javascript">
        function SelectMeOnly(objRadioButton, grdName) {
            var i, obj, pageElements;

            if (navigator.userAgent.indexOf("MSIE") != -1) {
                //IE browser
                pageElements = document.all;
            }
            else if (navigator.userAgent.indexOf("Mozilla") != -1 || navigator.userAgent.indexOf("Opera") != -1) {
                //FireFox/Opera browser
                pageElements = document.documentElement.getElementsByTagName("input");
            }
            for (i = 0; i < pageElements.length; i++) {
                obj = pageElements[i];

                if (obj.type == "radio") {
                    if (objRadioButton.id == obj.id) {
                        obj.checked = true;
                    }
                    else {
                        obj.checked = false;
                    }
                }
            }
        }
    </script>
</telerik:RadCodeBlock>
<telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">
    <AjaxSettings>
        <telerik:AjaxSetting AjaxControlID="SampleRadGrid">
            <UpdatedControls>
                <telerik:AjaxUpdatedControl ControlID="SampleRadGrid" LoadingPanelID="RadAjaxLoadingPanel1"></telerik:AjaxUpdatedControl>
            </UpdatedControls>
        </telerik:AjaxSetting>
    </AjaxSettings>
</telerik:RadAjaxManager>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel1" runat="server">
</telerik:RadAjaxLoadingPanel>
<telerik:RadAjaxLoadingPanel ID="RadAjaxLoadingPanel2" runat="server">
</telerik:RadAjaxLoadingPanel>
<div id="SampleDiv" class="MyGridClass" runat="server">
    <telerik:RadGrid ID="SampleRadGrid" Width="40%" AllowPaging="false" Class="MyGridClass" Skin="Office2010Silver" AutoGenerateColumns="False"
        AllowSorting="True"  OnNeedDataSource="SampleRadGrid_NeedDataSource" OnItemCreated="SampleRadGrid_ItemCreated"
        OnItemDataBound="SampleRadGrid_ItemDataBound" EnableLinqExpressions="true" OnInsertCommand="SampleRadGrid_InsertCommand" OnCancelCommand="SampleRadGrid_CancelCommand" runat="server"
        AllowMultiRowSelection="false" OnUpdateCommand="SampleRadGrid_UpdateCommand" OnDeleteCommand="SampleRadGrid_DeleteCommand">
        <ClientSettings>
            <Resizing ResizeGridOnColumnResize="true"/> <Selecting AllowRowSelect ="true" />
        </ClientSettings>
        <MasterTableView Caption="Select a G below, to manage linked another Grid" Font-Bold="true" Font-Size="Medium"  CommandItemDisplay="Top" DataKeyNames="GROUP_ID" ClientDataKeyNames="GROUP_ID">
            <CommandItemSettings ShowRefreshButton="false" AddNewRecordText="Add New Group" />
            <EditFormSettings>
                <PopUpSettings Modal="true" ZIndex="100010" />
            </EditFormSettings>
            <Columns>
                <telerik:GridTemplateColumn UniqueName="ManageGtemplateColumn" HeaderText="Select" HeaderStyle-Width="5%" Groupable="false" FilterControlWidth="60%">
                    <ItemTemplate>
                        <asp:RadioButton ID="rdSelectG" Text="" runat="server" ToolTip="Select a G to manage access" AutoPostBack="True" OnCheckedChanged="rdSelectG_CheckedChanged" />
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn DataField="G_ID" HeaderText="GId" UniqueName="GId" Visible="false" ReadOnly="True"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="G_NAME" HeaderText="G" HeaderStyle-Width="30%" UniqueName="G" ReadOnly="True"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="F_NAME" HeaderText="F" UniqueName="F" HeaderStyle-Width="30%" ReadOnly="True"></telerik:GridBoundColumn>
                <telerik:GridBoundColumn DataField="F_ID" HeaderText="FId" UniqueName="FId" ReadOnly="True" Visible="false"></telerik:GridBoundColumn>
                <telerik:GridEditCommandColumn UniqueName="EditCommandColumn" HeaderText="Edit" ButtonType="ImageButton" EditImageUrl="../images/edit.jpg" HeaderStyle-Width="3%" FilterControlWidth="60%"></telerik:GridEditCommandColumn>
                <telerik:GridButtonColumn UniqueName="DeleteColumn" Text="Delete" CommandName="Delete" HeaderText="Delete"  HeaderStyle-Width="5%"></telerik:GridButtonColumn>
            </Columns>
            <EditFormSettings EditFormType="Template">
                <FormTemplate>
                    <table id="Table2" class="MyGridClass" rules="none" style="border-collapse: collapse;">
                        <tr>
                            <td colspan="2" style="font-size: medium">
                                <b>M G</b>
                            </td>
                        </tr>
                        <tr>
                            <td>G Name:<telerik:RadTextBox ID="txtGN" MaxLength="50" runat="server" Text='<%# Bind("G_NAME") %>'>
                            </telerik:RadTextBox><br />
                                <asp:RequiredFieldValidator ID="reqValidatorTxtGrpName" runat="server" ControlToValidate="txtGName"
                                    ErrorMessage="*Please enter the G Name." Display="Dynamic" ForeColor="Red"></asp:RequiredFieldValidator>
                            </td>
                            <td>F Name:<telerik:RadComboBox ID="cbFName" Text="FName" runat="server"></telerik:RadComboBox>
                            </td>
                        </tr>
                        <tr>
                            <td align="center" colspan="2">
                                <asp:Button ID="rgBtnAddG" CausesValidation="true" Text='<%# (Container is GridEditFormInsertItem) ? "Insert" : "Update" %>' runat="server" CommandName='<%# (Container is GridEditFormInsertItem) ? "PerformInsert" : "Update" %>'></asp:Button>&nbsp;&nbsp;
                                <asp:Button ID="btnCancel" CausesValidation="false" Text="Cancel" runat="server" CommandName="Cancel"></asp:Button>
                            </td>
                        </tr>
                    </table>
                </FormTemplate>
            </EditFormSettings>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="False" />
        </ClientSettings>
    </telerik:RadGrid>
</div>
Posted
Updated 29-Jun-15 0:25am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900