Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

passing the value of a container.dataitem as a parameter in a javascript function inside a hyperlink control?

Posted on 2004-09-28
8
Medium Priority
?
2,337 Views
Last Modified: 2008-01-09
Hi There,

I am wanting to call a javascript function from inside a hyperlink control, the function works fine Its just not working when I try to put the value of a       Container.DataItem inside it. Is it legal to do this? I guess I'm probably missing a comma or something.

Sean - thanks in advance                  

<asp:HyperLink runat="server" Text="<%# DataBinder.Eval(Container.DataItem, &quot;shopname&quot;)%>" NavigateUrl="javascript:RefreshParent('<%# DataBinder.Eval(Container.DataItem, &quot;shop&quot;)%>');" ID="Hyperlink1"/>
0
Comment
Question by:bullrout
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 6

Expert Comment

by:viola123
ID: 12176738
follow this:

<a class="partname" href="partdetail.aspx" onclick="hideQstring('pt_recno', '<%# DataBinder.Eval(Container.DataItem, "pt_recno") %>')" target="_blank"><%# DataBinder.Eval(Container.DataItem, "pt_shortdesc") %></a>

cheers
viola
0
 
LVL 6

Expert Comment

by:viola123
ID: 12176740
and:

<IMG SRC="<%# findImage(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "pt_recno"))) %>" align="absMiddle" border="0"/>
0
 
LVL 6

Expert Comment

by:viola123
ID: 12176750
i don't think you have to use &quot;  

both of the two codes above are working on my page. so i believe yours should be all right.

cheers
viola
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 6

Accepted Solution

by:
viola123 earned 2000 total points
ID: 12176765
try these two:

1.
<asp:HyperLink runat="server" Text="<%# DataBinder.Eval(Container.DataItem, 'shopname')%>" onClick="javascript:RefreshParent('<%# DataBinder.Eval(Container.DataItem, "shop")%>')" ID="Hyperlink1"/>

2.
<a onClick="RefreshParent('<%# DataBinder.Eval(Container.DataItem, "shop")%>')">
<%# DataBinder.Eval(Container.DataItem, 'shopname')%>
</a>

regards,
viola
0
 
LVL 8

Expert Comment

by:boulder_bum
ID: 12176772
"Is it legal to do this?"

Yes.

As mentioned, &quot; should instead be a " (quotation mark).

Also, I've had problems before using double instead of single quotes for elements when binding (hopefully Microsoft has the problem fixed by now) so if you're still getting a funky error try changing:

Text="<%# ... %>"

  -to-

Text='<%# ... %>'
0
 
LVL 6

Expert Comment

by:viola123
ID: 12176796
my experience on that is:

text = "<%#...'myfunction("para")'%>"


wish it help

viola123
0
 
LVL 10

Expert Comment

by:jnhorst
ID: 12177135
In your databinding for the text property of the hyperlink, you are binding to "shopname" and then for your js call, you are binding to "shop".  Is this right?  Should "shop" be "shopname"?

Also, an option would be to have the column with the "shop" value you want to pass to RefreshParent() as a column in your grid (I am assuming that is your container?) that is marked as not visible.  Let's say that is column index #1.  You could use the ItemDataBound event and code like this:

if (e.Item.ItemType != ListItemType.Header && e.Item.ItemType != ListItemType.Footer)
{
     // resolve hyper link.  assuming it is in colunm index 2.  make sure you give your hyperlink control an id string (i'll use "hyperlinkName").
     HyperLink link = (HyperLink)e.Item.Cells[2].FindControl("hyperlinkName");

     // set NavigateUrl
     string shop = e.Item.Cells[1].Text;
     link.NavigateUrl = "javascript:RefreshParent('" + shop + "');";
}

John
0
 
LVL 5

Author Comment

by:bullrout
ID: 12177169
Hi guys, thanks for all the answers. The website is brillant for asp .net beginners like myself.

I appreciate the help.

Sean
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In .NET 2.0, Microsoft introduced the Web Site.  This was the default way to create a web Project in Visual Studio 2005.  In Visual Studio 2008, the Web Application has been restored as the default web Project in Visual Studio/.NET 3.x The Web Si…
Problem Hi all,    While many today have fast Internet connection, there are many still who do not, or are connecting through devices with a slower connect, so light web pages and fast load times are still popular.    If your ASP.NET page …
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question