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

how to get a value and focus of a rad grid control using javascript

2 Answers 158 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Madhuri
Top achievements
Rank 1
Madhuri asked on 29 Feb 2012, 08:01 AM
Hello Everybody,
In my Project i am using rad grid control. in the grid Dynamically I created text boxes and buttons for adding and editing i don't know how to put validations in java script. I used  the following code and it is not working. can you please help me

<telerik:RadGrid ID="SpGrid" runat="server" AllowMultiRowSelection="False"
    AllowPaging="True" AllowSorting="True" AutoGenerateColumns="false" PageSize="7"
    ShowStatusBar="true" Skin="Outlook">
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
    </HeaderContextMenu>
    <PagerStyle Mode="NumericPages" />
    <MasterTableView AllowMultiColumnSorting="True" CommandItemDisplay="Top" DataKeyNames="SPECIALITY_ID"
        Name="Specialist">
        <Columns>
            <telerik:GridEditCommandColumn HeaderText="Edit" UniqueName="EditCommandColumn">
                <ItemStyle Width="50px" />
            </telerik:GridEditCommandColumn>
            <telerik:GridBoundColumn DataField="SPECIALITY_ID"
                HeaderButtonType="TextButton" HeaderText="SPECIALITY ID"
                SortExpression="SPECIALITY_ID" UniqueName="SPECIALITY_ID">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="SPECIALITY_DESC"
                HeaderButtonType="TextButton" HeaderText="DESCRIPTION"
                SortExpression="SPECIALITY_DESC" UniqueName="SPECIALITY_DESC">
            </telerik:GridBoundColumn>
            <telerik:GridButtonColumn ButtonType="ImageButton" CommandName="Delete"
                ConfirmText="Delete this Specialist ?" Text="Delete" UniqueName="DeleteColumn1">
                <HeaderStyle Width="20px" />
                <ItemStyle CssClass="MyImageButton" HorizontalAlign="Center" />
            </telerik:GridButtonColumn>
        </Columns>
        <EditFormSettings EditFormType="Template">
            <FormTemplate>
                <table ID="tblSpecialitymaster" 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>SpecialityDetail</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>
                                        SpecialityID:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtSpId" runat="server" Font-Names="verdana"   Text='<%# Bind("SPECIALITY_ID") %>'
                                            Font-Size="8.5pt" MaxLength="50" TabIndex="1" ReadOnly="true">
                                                </asp:TextBox>
                                    </td>
                                </tr>
                                <tr>
                                    <td>
                                        Description:
                                    </td>
                                    <td>
                                        <asp:TextBox ID="txtSpDesc" runat="server" Font-Names="verdana"
                                            Font-Size="8.5pt" MaxLength="50" onkeypress=" return CharOnly('txtSpDesc',50)" TabIndex="2"
                                            Text='<%# Bind("SPECIALITY_DESC") %>' >
                                                </asp:TextBox>
                                                 
                                                <asp:RequiredFieldValidator ID="RFVSpDesc" runat="server" ErrorMessage="Enter Description."
                                                                ControlToValidate="txtSpDesc"></asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                    <tr>
                        <td align="right" colspan="2">
                            <asp:Button ID="btnUpdate3" Text='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "Insert", "Update") %>'
                                        Style="color: White; background-color: SteelBlue; font-family: Verdana; font-size: 8pt;
                                        width: 87px;" runat="server" CommandName='<%# IIf((TypeOf(Container) is GridEditFormInsertItem), "PerformInsert", "Update")%>'>
                                    </asp:Button>
                              
                            <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>
function valid() {
var grid = $find("<%=RadGridCountry.ClientID %>");
var detail= grid.get_detailTables()[0].get_dataItems()[0].findElement("txtSpDesc");
 
}
i trace that detail value it giving always null value

2 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 29 Feb 2012, 08:17 AM
Hello,

Check the following code library.
Accessing server controls in a grid template on the client

-Shinu.
0
Madhuri
Top achievements
Rank 1
answered on 29 Feb 2012, 11:06 AM
thank you shinu,

it's working fine.
Tags
Grid
Asked by
Madhuri
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Madhuri
Top achievements
Rank 1
Share this question
or