check radio buttonlist in edit mode inside rad grid

Thread is closed for posting
2 posts, 0 answers
  1. D6EA779B-E4F3-44C5-BA29-B3B2F3972137
    D6EA779B-E4F3-44C5-BA29-B3B2F3972137 avatar
    5 posts
    Member since:
    Feb 2012

    Posted 29 Feb 2012 Link to this post

    Requirements

    RadControls version

     2011

    .NET version

     3.0

    Visual Studio version

    2008 

    programming language

     vb

    browser support

    all browsers supported by RadControls

    Hi guys,
    I want to check the radio buttonlist while i will click on edit button in radgrid.Please help me out for this. I am putting the code what I am using now.

    PROJECT DESCRIPTION
    [enter description here, together with step-by-step instructions on how to use the project]

    <

    body>

     

     

    <form id="form1" runat="server">

     

     

    <div>

     

     

    <script language="javascript" type="text/javascript">

     

     

    function valid(e, mLength) {

     

     

    var keynum

     

     

    var keychar

     

     

    var numcheck

     

     

    if (window.event) // IE

     

    {

    keynum = e.keyCode;

    }

     

    else if (e.which) // Netscape/Firefox/Opera

     

    {

    keynum = e.which;

    }

    keychar = String.fromCharCode(keynum)

     

    // numcheck = /\d/

     

    numcheck =

    "";

     

     

    //return !numcheck.test(keychar)

     

     

    if ((keynum >= 65 && keynum <= 90) || (keynum >= 97 && keynum <= 122) || (keynum >= 48 && keynum <= 57) || (keynum == 32) || (keynum == 36) || (keynum == 38) || (keynum == 43) || (keynum == 64) || (keynum == 8)) {

     

     

    var tVal;

     

     

    var keycharacter = 0;

     

    tVal = keynum;

    keycharacter = String.fromCharCode(keynum);

    tVal = tVal + keycharacter;

     

    if (parseInt(tVal.length) > mLength) {

     

     

    return false;

     

    }

    }

    else { return false; }

     

    }

     

    </script>

     

     

    <script type="text/javascript">

     

     

    function GetGridServerElement(serverID, tagName) {

     

     

    if (!tagName)

     

    tagName =

    "*"; //* means all elements

     

     

    var grid = document.getElementById("<%=CategoryGrid.ClientID %>");

     

     

    var elements = grid.getElementsByTagName(tagName);

     

     

    for (var i = 0; i < elements.length; i++) {

     

     

    var element = elements[i];

     

     

    if (element.id.indexOf(serverID) >= 0)

     

     

    return element;

     

    }

    }

     

    function ValidName() {

     

     

    var serverID = "txtCatDesc";

     

     

    var tagName = "*"; //dropdowns render as <select> elements

     

     

    //var dropDown = GetRegisteredServerElement(serverID);

     

     

    var txtCatDesc = GetGridServerElement(serverID, tagName);

     

     

    if (txtCatDesc.value == '') {

     

    alert(

    'Enter Description');

     

    txtCatDesc.focus();

     

    return false;

     

    }

    }

     

    </script>

     

     

    <table bgcolor="white" width="98%">

     

     

    <tr>

     

     

    <!--#include file="../Menus/MenuPage.aspx"-->

     

     

    </tr>

     

     

    <tr>

     

     

    <td colspan="6" align="center">

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td colspan="6">

     

     

    <asp:UpdatePanel ID="UpdatePanel1" runat="server"><ContentTemplate>

     

     

    <table align="center">

     

     

    <tr>

     

     

    <td style="width: 100px">

     

     

    </td>

     

     

    <td align="center" >

     

     

    <asp:HyperLink ID="HyperLink1" runat="server" Font-Bold="True" Font-Names="Arial" Font-Size="Large" ForeColor="White" style="color:SteelBlue;font-family:Verdana;font-size:14pt;font-weight:bold;text-decoration:underline;">Category Master</asp:HyperLink></td>

     

     

    <td class="style2">

     

     

    &nbsp;</td>

     

     

    </tr>

     

    <%

    --<tr>

     

    <td>

    <asp:Label ID="lblSpeCode" runat="server" Text="Category Code" Width="108px" Font-Bold="False" style="color:Maroon;font-family:Verdana;font-size:8.5pt;font-weight:normal;"></asp:Label></td>

    <td>

    <asp:TextBox ID="txtSpeCode" runat="server" ReadOnly="True" Width="120px" TabIndex="1" style="color:Black;background-color:White;font-family:Verdana;font-size:8.5pt;"></asp:TextBox>

    <asp:DropDownList ID="ddlSpeCode" runat="server" MaxLength="50"

    style="color:Black;background-color:White;font-family:Verdana;font-size:8.5pt;"

    TabIndex="2" Width="220px" AutoPostBack="True">

    </asp:DropDownList>

    <span style="font-size: 8pt; color: #800000">*</span></td>

    <td>

    &nbsp;</td>

    </tr>--

    %>

     

    <%

    --<tr>

     

    <td>

    <asp:Label ID="lblDescription" runat="server" Text="Description" Width="85px" Font-Bold="False" style="color:Maroon;font-family:Verdana;font-size:8.5pt;font-weight:normal;"></asp:Label></td>

    <td>

    <asp:TextBox ID="txtDescription" runat="server" MaxLength="50" Width="220px" TabIndex="2" style="color:Black;background-color:White;font-family:Verdana;font-size:8.5pt;"></asp:TextBox>

    <asp:DropDownList ID="ddlDescription" runat="server" MaxLength="50"

    Width="220px" TabIndex="2"

    style="color:Black;background-color:White;font-family:Verdana;font-size:8.5pt;"

    AutoPostBack="True">

    </asp:DropDownList>

    <span style="font-size: 8pt; color: #800000">*</span></td>

    <td>

    &nbsp;</td>

    </tr>--

    %>

     

    <%

    --<tr>

     

    <td>

    <asp:Label ID="lblDescription0" runat="server" Font-Bold="False"

    style="color:Maroon;font-family:Verdana;font-size:8.5pt;font-weight:normal;"

    Text="Percentage" Width="85px"></asp:Label>

    </td>

    <td>

    <asp:TextBox ID="txtSpeCode0" runat="server" ReadOnly="True"

    style="color:Black;background-color:White;font-family:Verdana;font-size:8.5pt;"

    TabIndex="1" Width="120px"></asp:TextBox>

    %</td>

    <td>

    &nbsp;</td>

    </tr>--

    %>

     

     

    <tr>

     

     

    <td style="width: 100px">

     

     

    &nbsp;</td>

     

     

    <td align="center">

     

     

     

    </td>

     

     

    <td class="style2">

     

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td colspan="3">

     

     

    <telerik:RadGrid ID="CategoryGrid" runat="server" AllowMultiRowSelection="False"

     

     

    AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false"

     

     

    ShowStatusBar="true" Skin="Outlook">

     

     

    <headercontextmenu cssclass="GridContextMenu GridContextMenu_Default">

     

     

    </headercontextmenu>

     

     

    <PagerStyle AlwaysVisible="true"/>

     

     

    <mastertableview allowmulticolumnsorting="True" commanditemdisplay="Top"

     

     

    datakeynames="CATCOD" name="Category">

     

     

    <Columns>

     

     

    <telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn" ButtonType="ImageButton">

     

     

    <ItemStyle Width="50px" />

     

     

    </telerik:GridEditCommandColumn>

     

     

    <telerik:GridBoundColumn DataField="CATCOD"

     

     

    HeaderButtonType="TextButton" HeaderText="CATEGORY CODE"

     

     

    SortExpression="CATCOD" UniqueName="CATCOD">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="DESCRIPTION"

     

     

    HeaderButtonType="TextButton" HeaderText="DESCRIPTION"

     

     

    SortExpression="DESCRIPTION" UniqueName="DESCRIPTION">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="per"

     

     

    HeaderButtonType="TextButton" HeaderText="PERCENTAGE"

     

     

    SortExpression="per" UniqueName="per">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridBoundColumn DataField="deptwacc"

     

     

    HeaderButtonType="TextButton" HeaderText="DEPT WISE ACCOMODATION"

     

     

    SortExpression="deptwacc" UniqueName="deptwacc">

     

     

    </telerik:GridBoundColumn>

     

     

    <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"

     

     

    ConfirmText="Delete this Category ?" Text="Delete" UniqueName="DeleteColumn1">

     

     

    <HeaderStyle Width="20px" />

     

     

    <ItemStyle CssClass="MyImageButton" HorizontalAlign="Center" />

     

     

    </telerik:GridButtonColumn>

     

     

    </Columns>

     

     

    <editformsettings editformtype="Template">

     

     

    <formtemplate>

     

     

    <table id="tblCategoryMaster" border="1" cellpadding="1" cellspacing="2"

     

     

    rules="none" style="border-collapse: collapse; background: white;" width="100%">

     

     

    <tr class="EditFormHeader">

     

     

    <td colspan="2" style="font-size: small; font-family: Verdana;color:Maroon">

     

     

    <b>CategoryDetail</b>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td>

     

     

    <table id="Table3" border="0" cellpadding="1" cellspacing="1" class="module"

     

     

    width="250">

     

     

    <tr>

     

     

    <td>

     

     

    </td>

     

     

    <td>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td >

     

     

    <asp:Label ID="label2" Text="Category Code:" runat="server" Font-Names="verdana" Font-Size="8.5pt"

     

     

    ForeColor="Maroon"></asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="txtCatCod" runat="server" Font-Names="verdana" Font-Size="8.5pt"

     

     

    MaxLength="50" ReadOnly="true" TabIndex="1" Text='<%# Bind("CATCOD") %>'>

     

     

    </asp:TextBox>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td >

     

     

    <asp:Label ID="label1" Text="Description:" runat="server" Font-Names="verdana" Font-Size="8.5pt"

     

     

    ForeColor="Maroon"></asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="txtCatDesc" runat="server" Font-Names="verdana"

     

     

    Font-Size="8.5pt" MaxLength="50" onkeypress=" return valid(event,50)"

     

     

    TabIndex="2" Text='<%# Bind("DESCRIPTION") %>'>

     

     

    </asp:TextBox>

     

     

    <asp:RequiredFieldValidator ID="RFVCatDesc" runat="server"

     

     

    ControlToValidate="txtCatDesc" ErrorMessage="Enter Description."></asp:RequiredFieldValidator>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td >

     

     

    <asp:Label ID="label4" Text="Percentage:" runat="server" Font-Names="verdana" Font-Size="8.5pt"

     

     

    ForeColor="Maroon"></asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:TextBox ID="txtperc" runat="server" Font-Names="verdana"

     

     

    Font-Size="8.5pt" MaxLength="50" TabIndex="3" Text='<%# Bind("per") %>'>

     

     

    </asp:TextBox>%

     

    <%

    --<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"

     

    ControlToValidate="txtCatDesc" ErrorMessage="Enter Percentage."></asp:RequiredFieldValidator>--

    %>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td >

     

     

    <asp:Label ID="label3" Text="Dept Wise Accomodation:" runat="server" Font-Names="verdana" Font-Size="8.5pt"

     

     

    ForeColor="Maroon"></asp:Label>

     

     

    </td>

     

     

    <td>

     

     

    <asp:RadioButtonList ID="RadBtnLst" runat="server" TabIndex="4" Font-Names="verdana"

     

     

    Font-Size="8.5pt" RepeatDirection="Horizontal" DataValueField='<%# Bind("deptwacc") %>'>

     

     

    <asp:ListItem>Yes</asp:ListItem>

     

     

    <asp:ListItem>No</asp:ListItem>

     

     

    </asp:RadioButtonList>

     

    <%

    --<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"

     

    ControlToValidate="RadBtnLst" ErrorMessage="Select Dept wise accomodation."></asp:RequiredFieldValidator>--

    %>

     

     

    </td>

     

     

    </tr>

     

     

    </table>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="right" colspan="2">

     

     

    <asp:Button ID="btnUpdate3" runat="server" OnClientClick="return ValidName()"

     

     

    CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>' Style="color: White; background-color: SteelBlue; font-family: Verdana; font-size: 8pt;

     

    width: 87px;"

     

     

    Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'/>

     

     

    &nbsp;

     

     

    <asp:Button ID="btnCancel3" runat="server" CausesValidation="False"

     

     

    CommandName="Cancel" Style="color: White; background-color: SteelBlue; font-family: Verdana;

     

    font-size: 8pt; width: 87px;"

    Text="Cancel" />

     

     

    </td>

     

     

    </tr>

     

     

    </table>

     

     

    </formtemplate>

     

     

    </editformsettings>

     

     

    </mastertableview>

     

     

    </telerik:RadGrid>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="center" colspan="3" style="font-size: 9%">

     

    <%

    --<table>

     

    <tr>

    <td>

    <asp:Button ID="btnAdd" runat="server" AccessKey="A" Text="Add" ToolTip="Alt+a" Width="87px" TabIndex="3" style="color:White;background-color:SteelBlue;font-family:Verdana;font-size:8.5pt;"/></td>

    <td>

    <asp:Button ID="BtnSave" runat="server" AccessKey="S" OnClick="btnSave_Click" Text="Save"

    ToolTip="Alt+s" Width="87px" TabIndex="4" style="color:White;background-color:SteelBlue;font-family:Verdana;font-size:8.5pt;" /></td>

    <td>

    <asp:Button ID="btnEdit" runat="server" AccessKey="E" Text="Edit" ToolTip="Alt+e"

    Width="83px" TabIndex="5" style="color:White;background-color:SteelBlue;font-family:Verdana;font-size:8.5pt;"/></td>

    <td>

    &nbsp;<asp:Button ID="btnDel" runat="server" AccessKey="L" Text="Delete" ToolTip="Alt+l"

    Width="83px" TabIndex="6" style="color:White;background-color:SteelBlue;font-family:Verdana;font-size:8.5pt;"/></td>

    <td>

    <asp:Button ID="btnClear" runat="server" AccessKey="C" Text="Clear" ToolTip="Alt+c"

    Width="83px" TabIndex="7" style="color:White;background-color:SteelBlue;font-family:Verdana;font-size:8.5pt;"/></td>

    <td>

    <asp:Button ID="btnView" runat="server" AccessKey="V" Text="View" ToolTip="Alt+v"

    Width="83px" TabIndex="8" style="color:White;background-color:SteelBlue;font-family:Verdana;font-size:8.5pt;"/></td>

    </tr>

    </table>--

    %>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td align="center" colspan="3">

     

     

    <asp:Label ID="lblResult" runat="server" Font-Bold="True" Font-Names="Verdana" Font-Size="Small"

     

     

    ForeColor="Maroon" Width="448px"></asp:Label>

     

     

    <asp:TextBox ID="txtSpeNo" runat="server" BorderStyle="None" ForeColor="White" Height="1px"

     

     

    Width="1px"></asp:TextBox></td>

     

     

    </tr>

     

     

    </table>

     

     

    </ContentTemplate>

     

     

    </asp:UpdatePanel>

     

     

    </td>

     

     

    </tr>

     

     

    <tr>

     

     

    <td colspan="6">

     

     

    <uc1:footer ID="footer2" runat="server" />

     

     

    </td>

     

     

    </tr>

     

     

    </table>

     

     

    </div>

     

     

    </div>

     

     

    </form>

     

    </

    body>

     

    </

    html>

     


  2. 2B755ED1-9557-4032-A918-C0CF8A4F6331
    2B755ED1-9557-4032-A918-C0CF8A4F6331 avatar
    836 posts
    Member since:
    Feb 2017

    Posted 05 Mar 2012 Link to this post

    Hello,

    You could use the following VB code in order to achieve your goal:

    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)Handles RadGrid1.ItemDataBound
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim editForm As GridEditFormItem = TryCast(e.Item, GridEditFormItem)
            Dim radioList As RadioButtonList = TryCast(editForm.FindControl("RadBtnLst"), RadioButtonList)
            radioList.SelectedIndex = 0
        End If
    End Sub

    Give this code a try and check whether this is the desired behavior.

    Regards,
    Andrey
    the Telerik team
    If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Back to Top

This Code Library is part of the product documentation and subject to the respective product license agreement.