From: Tony WONG on
This is a Label in ItemTemplate

i wish to use javascript to put <%# Eval("Organization") %> in a textbox

How can i take the text value of <%# Eval("Organization") %>?

put this - onmousedown="alert(<%# Eval("�ӽо��c") %>)" ???

thanks for any ideas?

***********************
<asp:Label ID="Label11" runat="server" Text='<%# Eval("Organization") %>'
></asp:Label>
&nbsp;<asp:Label ID="Label2" runat="server" Text='<%# Eval("Department") %>'
</asp:Label>


From: Mark Rae [MVP] on
"Tony WONG" <x34(a)netvigator.com> wrote in message
news:OMELVAEiKHA.5520(a)TK2MSFTNGP06.phx.gbl...

> This is a Label in ItemTemplate
>
> i wish to use javascript to put <%# Eval("Organization") %> in a textbox
>
> How can i take the text value of <%# Eval("Organization") %>?
>
> put this - onmousedown="alert(<%# Eval("�ӽо��c") %>)" ???
>
> thanks for any ideas?
>
> ***********************
> <asp:Label ID="Label11" runat="server" Text='<%# Eval("Organization") %>'
> ></asp:Label>
> &nbsp;<asp:Label ID="Label2" runat="server" Text='<%# Eval("Department")
> %>' </asp:Label>

I'm not quite sure what you're asking. Do you need to reference the contents
of an asp:Label in client-side JavaScript?

If so, then all you need to know is that an asp:Label is rendered as an HTML
<span />. Therefore:

<script type = "text/javascript">
var label1 = document.getElementById('<%=Label1.ClientID%>');
var label1Text = label1.innerText;
</script>

BTW, you really should consider giving your controls more meaningful and
descriptive names than "Label1", "Label2" etc...


--
Mark Rae
ASP.NET MVP
http://www.markrae.net

From: Tony WONG on
Thank you for your patient to listen my problem

I tried many solutions for a few hours and still fail
the problem is how to retrieve the label text in a itemTemplate of a
Gridview

***** asp.net *************
<ItemTemplate>
<asp:Label ID="LbOrg" runat="server" Text='<%# Eval("Org") %>'
onmousedown='SearchOrg();'></asp:Label>
</ItemTemplate>

try many ways, return error "LbOrg not declared"
****** javascript *********
var controlId = document.getElementById('<%=LbOrg.ClientID%>').text;
var controlId = document.getElementById('<%=LbOrg.ClientID%>').value;
var controlId = document.getElementById('<%=LbOrg.ClientID%>').innerText;
var controlId = document.getElementById('<%=LbOrg.ClientID%>').innerHTML;

********* html ******************
<span id="GridView1_ctl02_LbOrg" onmousedown="SearchOrg();">Organization
name</span>

i know there is a long solution by assigning index at rowdatabound, and
javascript retrieve parameter of the row index

but it seems asp.net solution is much shorter.

Grateful for any assistance. thx.




"Mark Rae [MVP]" <mark(a)markNOSPAMrae.net>
???????:Oi%23yyyIiKHA.5596(a)TK2MSFTNGP05.phx.gbl...
> "Tony WONG" <x34(a)netvigator.com> wrote in message
> news:OMELVAEiKHA.5520(a)TK2MSFTNGP06.phx.gbl...
>
>> This is a Label in ItemTemplate
>>
>> i wish to use javascript to put <%# Eval("Organization") %> in a textbox
>>
>> How can i take the text value of <%# Eval("Organization") %>?
>>
>> put this - onmousedown="alert(<%# Eval("�ӽо��c") %>)" ???
>>
>> thanks for any ideas?
>>
>> ***********************
>> <asp:Label ID="Label11" runat="server" Text='<%# Eval("Organization") %>'
>> ></asp:Label>
>> &nbsp;<asp:Label ID="Label2" runat="server" Text='<%# Eval("Department")
>> %>' </asp:Label>
>
> I'm not quite sure what you're asking. Do you need to reference the
> contents of an asp:Label in client-side JavaScript?
>
> If so, then all you need to know is that an asp:Label is rendered as an
> HTML <span />. Therefore:
>
> <script type = "text/javascript">
> var label1 = document.getElementById('<%=Label1.ClientID%>');
> var label1Text = label1.innerText;
> </script>
>
> BTW, you really should consider giving your controls more meaningful and
> descriptive names than "Label1", "Label2" etc...
>
>
> --
> Mark Rae
> ASP.NET MVP
> http://www.markrae.net