First I was changing HyperLink.NavigateUrl in code-behind on Page_Load().
But after I decided to do it in design using Eval() method.
<asp:HyperLink runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Eval("type"), Eval("id")) %>' Text="Refuse" />
or
<asp:HyperLink ID="urlRefuse" runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
where id and type - are variables from Request.
But it doesn't work. Only raw text 'Refuse' is shown. Where is my mistake? Thanks in advance.
this is working great
NavigateUrl='<%# Eval("type","~/Refuse.aspx?type={0}") %>'
This worked for me
NavigateUrl='<%# String.Format("{0}.aspx?ID={1}", DataBinder.Eval(Container.DataItem, "Category"), DataBinder.Eval(Container.DataItem, "Post_ID")) %>'
Try and ViewSource in your browser, what's being rendered to the client in your href? Is it what you expected?. If you are trying to use variables from the request collection you can't use Eval, you need to use the Request query string parameters.
<asp:HyperLink runat="server"
NavigateUrl='<%# String.Format("~/Refuse.aspx?type={0}&id={1}", Request["type"], Request["id"]) %>' Text="Refuse" />
Try this:
HttpUtility.UrlEncode(Eval("type")
Try this one:
<asp:HyperLink ID="HyperLink2" runat="server" onclick='<%# String.Format("AcceptUser({0},{1})",Eval("UserId"), Eval("TsId")) %>' NavigateUrl="javascript:void(0)" Visible='<%# (bool)Eval("CanDelete") %>'>Accept</asp:HyperLink>
Try this it worked for me:
Eval("type").ToString()
Related
I have one gridview in which i'm binding a List of Website names like
www.google.com
www.facebook.com
www.gmail.com
www.google.com
www.facebook.com
www.gmail.com
Now, I want to redirect to www.google.com when i click on this
I used this one but its not working
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Website", #"{0:hh\:mm}") %>' Text='<%# Eval("Website", #"{0:hh\:mm}") %>' Target="_blank"></asp:HyperLink>
You should include "http://" before your redirect link.Please go through the below example,
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("Website","http://{0}") %>' Text='<%# Eval("Website") %>' Target="_blank"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
OR
<asp:TemplateField>
<ItemTemplate>
<%# Eval("Website") %>
</ItemTemplate>
</asp:TemplateField>
Make sure the NavigateUrl has http:// or https:// in it, otherwise the browser will think it is a link in the same domain.
NavigateUrl='<%# "https://" + Eval("Website", #"{0:hh\:mm}") %>'
Or if some website do have that http in them but others don't, you can check for that first
NavigateUrl='<%# Eval("Website").ToString().Contains("http") ? Eval("Website") : "https://" + Eval("Website") %>'
lets say i have the following link stackoverflow.com stored in db.
When i click the link from grid-view it redirect me to below path
http://localhost:30987/Main/stackoverflow.com
Note I am taking user input so i cant add http:// to user input because i cant determine the user website use HTTP or HTTPS
How can i solve this issue ?
<asp:TemplateField HeaderText="Website" SortExpression="Website">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Target="_blank" Text='<%# Bind("Websitelink") %>' NavigateUrl='<%# Bind("Websitelink") %>' runat="server"></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
As like Andrei mentioned in the comment, use HtmlAnchor(<a>) instead for <asp:HyperLink to make it work. You code will looks like the following:
<asp:TemplateField HeaderText="Website" SortExpression="Website">
<ItemTemplate>
<%#Eval("Websitelink") %>
</ItemTemplate>
</asp:TemplateField>
I am using <asp:HyperLink> in Gridview
<asp:HyperLink ID="hyperlink1" runat="server" ImageUrl="~/images/zoom.png" OnClick="javascript:window.open('ProductSummary.aspx?id=', 'open_window', 'width=640, height=480, left=0, top=0')"></asp:HyperLink>
I need to know that how to pass '<%# Eval("ProductId") %>' in query string
Probably the easiest way is to produce the entire OnClick event in the DataSource for the grid view, and bind to that:
<asp:HyperLink ID="hyperlink1" runat="server" ImageUrl="~/images/zoom.png"
OnClick='<%# Eval("PopupClickEvent") %>' ... />
Otherwise, it should still be possible to have
OnClick='<%# Eval("ProductID", "javascript:window.open('ProductSummary.aspx?id={0}', ...)") %>'
But the quotation escaping gets messy and confusing very quickly.
For reference, see http://msdn.microsoft.com/en-us/library/4hx47hfe(v=vs.110).aspx
When I use:
<asp:Label id="lbCatId" runat="server" Text='<%# Eval("VideoId") %>' Visible="true" />
I get:
<span id="ctl00_mainContent_ucCoverFlow_rptVideos_ctl00_lbCatId">5</span>
However when I use:
<asp:Image runat="server" href='Play.aspx?VideoId=<%# Eval("VideoId") %>' ID="iThumbnailFileName" CssClass="content" />
I get:
<img id="ctl00_mainContent_ucCoverFlow_rptVideos_ctl01_iThumbnailFileName" class="content" href="Play.aspx?VideoId=<%# Eval("VideoId") %>"
I would like to know why C# isn't generating the 'VideoId' like it is in the first example.
You are printing the string of the command you want to execute instead of executing it.
Use :
'<%# "Play.aspx?VideoId=" + Eval("VideoId") %>'
Instead of :
'Play.aspx?VideoId=<%# Eval("VideoId") %>'
Try using the ImageUrl property instead. The href attribute probably doesn't know how to interpret databinding syntax.
<asp:Image ID="Image1" runat="server" ImageUrl='Play.aspx?VideoId=<%# Eval("VideoId") %>' ...>
Have you tried:
<asp:Image runat="server" href='<%# "Play.aspx?VideoId=" + Eval("VideoId") %>' ID="iThumbnailFileName" CssClass="content" />
Try to change:
href='Play.aspx?VideoId=<%# Eval("VideoId") %>'
to
href='<%# "Play.aspx?VideoId=" + Eval("VideoId") %>'
'<%# Eval("VideoId","Play.aspx?VideoId={0}") %>'
I am not able to sent the value of the MachineID to another page using the hyperlink in gridview.
<!-- <asp:TemplateField HeaderText="FailedFiles"
SortExpression="NumFailedFilesOverSLA">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
Text='<%#Bind("NumFailedFilesOverSLA") %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
I have tried putting
DataNavigateUrlFields="MachineID"
DataNavigateUrlFormatString="GetFilesFailed.aspx?id={0}"
but don't know why this is not working??
Please suggest...
thanks
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# Eval("Inventory_ID", "/default.aspx?ID={0}") %>'
Text="Details"></asp:HyperLink>
</ItemTemplate>
This should solve your problem. This is exactly how I used it.
If this doesn't work, then check that you are actually getting a value back from the DB for MachineID:
<asp:HyperLink ID="HyperLink1" Text='<%# Bind("NumFailedFilesOverSLA") %>'
runat="server" DataNavigateUrlFields="MachineID"
DataNavigateUrlFormatString="GetFilesFailed.aspx?id={0}">
</asp:HyperLink>
First, try to put the default gridview in the page and attach it to the data source, so you can test if there is data to display.
If you are assigning the data source from code behind don't forget to call the DataBind() method after that.