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.
Related
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>
Please refer to the code below. The template field is a part of a gridview. I have a requirement where I want to pass the string from Boundfield "TriggerEvent" to a method "Alert()" that should do some operation on the string and display it back in the grid. I have encountered error in this which is explainable. How do I achieve this functionality?
<asp:TemplateField HeaderText="TriggerEvent" SortExpression="TriggerEvent" ItemStyle- Wrap="false">
<ItemTemplate>
<asp:Label ID="Label1" runat="server" Text='<%# Alert(Eval("TriggerEvent")) %>'></asp:Label>
</ItemTemplate>
<EditItemTemplate>
As Eval is returning object and Alert is expecting string, you can cast is with as:
Text='<%# Alert(Eval("TriggerEvent") as string) %>'
I have a HyperLink along with other controls such as Label etc in a GridView. The Label's in the GridView are dynamically populated like this:
<asp:Label ID="Label1" runat="server" Text='<%# Bind("ClientName") %>'></asp:Label>
I am now trying to do something similar with HyperLink, as in:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='http://www.company.com?clientname=<%# Bind("ClientName") %>'>Client Name</asp:HyperLink>
This doesn't give me any errors, but the link becomes this:
http://www.company.com/?clientname=<%# Bind("ClientName") %>
instead of something like this:
http://www.company.com/?clientname=oshiro
Anyone know how to get the link to work properly instead of just outputing the asp.net code?
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("ClientName", "http://www.company.com/?id={0}") %>'>Client Name</asp:HyperLink>
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
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()