Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 2410
  • Last Modified:

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

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
bullrout
Asked:
bullrout
1 Solution
 
viola123Commented:
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
 
viola123Commented:
and:

<IMG SRC="<%# findImage(Convert.ToInt32(DataBinder.Eval(Container.DataItem, "pt_recno"))) %>" align="absMiddle" border="0"/>
0
 
viola123Commented:
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
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
viola123Commented:
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
 
boulder_bumCommented:
"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
 
viola123Commented:
my experience on that is:

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


wish it help

viola123
0
 
jnhorstCommented:
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
 
bullroutAuthor Commented:
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

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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now