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

Newbie Q: How do I read a label from a grid in javascript?

5 Answers 160 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Daniel
Top achievements
Rank 1
Daniel asked on 31 Mar 2011, 10:30 AM
Hi,

Please excuse the level I'm posting in these forums at, I'm rather new to asp.net let alone telerik controls.

Basically, I have created a radgrid, in this radgrid is the following column template:

[code]
                                    <telerik:GridTemplateColumn UniqueName="completedDateTime" HeaderText="Completed Date & Time">
                                        <ItemStyle HorizontalAlign="Center" />
                                        <ItemTemplate>
                                            <asp:Label ID="lblCompletedDateTime" runat="server"></asp:Label>
                                        </ItemTemplate>
                                    </telerik:GridTemplateColumn>
[/code]

What I want to do basically is onrowselect - read the TEXT property of lblCompletedDateTime in javascript.

I usually refer to the clientid or the rendered id of the label (using $find) but I obviously need to identify it per row which is where I'm stuck.

Thanks a lot!!

Dan

p.s. Sorry about the code there!? Thought they were the code tags.

5 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 31 Mar 2011, 10:58 AM
Hello Daniel,

Try the following client side code tin the OnRowSelecting event to access the Label control which is inside ItemTemplate.

function OnRowSelecting(sender, args)
    {
       var label1 = args.get_gridDataItem().findElement("lblCompletedDateTime");
       alert(label1.innerText);
    }

Thanks,
Shinu.
0
Daniel
Top achievements
Rank 1
answered on 31 Mar 2011, 10:59 AM
Thanks a lot Shinu, I was hoping you'd reply to be honest - seem to be answering most of the questions on here first time, I'll give it a go now and let you know...
0
Daniel
Top achievements
Rank 1
answered on 31 Mar 2011, 11:04 AM
Hi Shinu,

On row selecting it spat out the following error: "Microsoft JScript runtime error: 'get_gridDataItem()' is null or not an object."

On the grid this is how I've referred to the javascript:

<telerik:RadGrid ClientSettings-ClientEvents-OnRowSelecting="gridCorrectiveActions_RowSelecting" OnItemDataBound="gridCorrectiveActions_ItemDataBound" DataSourceID="CorrectiveActionsDS"
ID="gridCorrectiveActions" AutoGenerateColumns="False" runat="server" GridLines="None"
Height="95%" ShowFooter="true">
0
Accepted
Princy
Top achievements
Rank 2
answered on 31 Mar 2011, 12:55 PM
Hello Daniel,

The get_gridDataItem() is not directly available on the client unless OnRowCreating/OnRowCreated events are hooked up. This is done for optimization purpose. If you need the rowIndex, you can use eventArgs.get_itemIndexHierarchical().

Take a look at the following documentation as well.
OnRowSelecting

Thanks,
Princy.
0
Daniel
Top achievements
Rank 1
answered on 31 Mar 2011, 12:58 PM
Thanks a lot for both of those replies, finally solved it!!
Tags
General Discussions
Asked by
Daniel
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Daniel
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Share this question
or