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

Get Label Text in Radgrid client-side

3 Answers 235 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Marc Plaxton-Harrison
Top achievements
Rank 1
Marc Plaxton-Harrison asked on 12 Oct 2009, 10:42 AM
Hi All,

i am having a problem, i am using a radgrid with a label called "lblID" inside the ItemTemplate of the grid.

Is there a way i can get the labels text using JavaScript??

my code:

function RowDblClick()
{
Code to go here!!
}

my Grid:

<Columns>
                <telerik:GridTemplateColumn HeaderText="ID" UniqueName="ID" Visible="False">
                    <ItemTemplate>
                        <asp:Label ID="lblID" runat="server" Visible="true" Text='<%# Eval("ID") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                 <telerik:GridTemplateColumn HeaderText="Name" UniqueName="Name">
                    <ItemTemplate>
                        <asp:Label ID="lblName" runat="server" Text='<%# Eval("Name") %>'></asp:Label>
                    </ItemTemplate>
                     <HeaderStyle Width="50%" />
                     <ItemStyle Width="50%" />
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Date" UniqueName="TemplateColumn21">
                    <ItemTemplate>
                        <asp:Label ID="lblDate" runat="server" Text='<%# Eval("Date") %>'></asp:Label>
                    </ItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridTemplateColumn HeaderText="Edit" UniqueName="TemplateColumn2" Visible="False">
                    <ItemTemplate>
                        <asp:HyperLink ID="hprEdit" runat="server" Target="_blank">Edit</asp:HyperLink>
                    </ItemTemplate>
                    <FooterStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False"
                        Font-Underline="False" Wrap="True" />
                    <ItemStyle Font-Bold="False" Font-Italic="False" Font-Overline="False" Font-Strikeout="False" Font-Underline="False" Wrap="True" />
                </telerik:GridTemplateColumn>
            </Columns>
<ClientSettings EnablePostBackOnRowClick="True" AllowExpandCollapse="False" AllowGroupExpandCollapse="False">
                            <ClientEvents OnRowDblClick="RowDblClick" />
                            <Selecting AllowRowSelect="True"/>
                            <Scrolling AllowScroll="True" UseStaticHeaders="True" />
</ClientSettings>

please help!?!?!?!

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 12 Oct 2009, 11:18 AM
Hi Marc Plaxton,

You can use following approach to get the DOM element of Label placed in ItemTemplate of RadGrid.

JavaScript:
 
<script type="text/javascript"
    function OnRowDblClick(sender, args) { 
        var item = args.get_item(); 
        var label = $telerik.findElement(item.get_element(), "lblID"); 
        alert(label.innerHTML); 
    } 
    function OnRowCreated() { 
 
    } 
</script> 

-Shinu.
0
Marc Plaxton-Harrison
Top achievements
Rank 1
answered on 12 Oct 2009, 11:38 AM
Hi Shinu,

i added the function but with no success, i receive the following error:

Message: 'null' is null or not an object

0
Shinu
Top achievements
Rank 1
answered on 13 Oct 2009, 01:01 PM
Hi Marc Plaxton,

Have you attached OnRowCreated event to RadGrid? get_item() is not directly available on the client unless OnRowCreating/OnRowCreated events are hooked up.

aspx:
 
<ClientSettings> 
    <ClientEvents OnRowCreated="OnRowCreated"  OnRowDblClick="OnRowDblClick" /> 
</ClientSettings> 

-Shinu.
Tags
Grid
Asked by
Marc Plaxton-Harrison
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Marc Plaxton-Harrison
Top achievements
Rank 1
Share this question
or