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
2,061 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
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
 
LVL 6

Accepted Solution

by:
viola123 earned 500 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
How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Lots of people ask this question on how to extend the “MembershipProvider” to make use of custom authentication like using existing database or make use of some other way of authentication. Many blogs show you how to extend the membership provider c…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

760 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now