I have created an DataList with Hyperlinks inside of it. But... It's redirecting me to for example: /itemName, but i want to redirect it to /itemName.aspx. When i add to the Eval .aspx its putting an error.
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" Width="120px">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("itemName") %>' Text='<%# Eval("nazwa") %>'></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
Any ideas?
Problem solved by editing Eval like this:
Eval("itemName", "~/{0}.aspx")
Related
Is it possible to access the Text of ProductName inside this Hyperlink (DATALIST) ?
Thank you!!
<asp:DataList ID="DataList1" runat="server" CellPadding="0" RepeatColumns="4" RepeatDirection="Horizontal" ShowFooter="False" ShowHeader="False" OnSelectedIndexChanged="DataList1_SelectedIndexChanged">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" Text='<%# Eval("productName") %>' runat="server" Font-Size="Large"></asp:HyperLink>
</ItemTemplate>
</asp:DataList>
I have a logLink column in my database.
I have my hyperlink field in gridView as below :
<asp:HyperLinkField DataNavigateUrlFields="logLink" DataTextField="logLink" DataNavigateUrlFormatString="{0}" Text="Link" ControlStyle-CssClass="hlink" HeaderText="LOG LINK" ItemStyle-Width="6%" ItemStyle-Font-Underline="true" />
But this link is not clickable.
I want the values in the log link column of my db to come here.
Does anyone know how to solve this ?
try this.
<asp:TemplateField>
<ItemTemplate>
<asp:HyperLink ID="lnk" runat="server" Target="_blank" Text='<%# Eval("yourText") %>'
NavigateUrl='<%# Eval("logLink") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
I am new to this:
In Visual Studio 2010, asp.net
Webpage A has a gridview with a column of hyperlink of companyid:
<asp:TemplateField HeaderText="Company" ItemStyle-Width="20%" >
<ItemTemplate>
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1"
Target="_blank" runat="server"
NavigateUrl= WHAT SHOULD I PUT HERE TO NAVIGATE TO PAGE B WHICH IS ALSO IN THE SOLUTION
</ItemTemplate>
</asp:TemplateField>
I want to navigate to another page that's also in the solution file, but I don't know what address to use as it's not some links that's hosted already like "google.ca"
For the new webpage, I don't want any buttons or like that, I just want a page to show the details of a company, using "select * from table where companyid= 'value_from_pageA_hyperlink'. How can I build the page so that it's url could be something like www.somepage/key=?" Or can I set up a global value so that I can pass the companyid in the hyperlink to the other page?
I have been crazed by those.
Use
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1" Target="_blank" runat="server"
NavigateUrl='~/PageB.aspx?companyId=<%# Eval("CompanyID")%>'/>
"~/" in an ASP.NET URL means that the address is relative to the current application.
You Can Send A Query String And Get it Through request.params
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1"
Target="_blank" runat="server"
NavigateUrl="page2.aspx?variablename=value"/>
and get it through
request.params["variablename"]
on another page
I think it Should work
http://msdn.microsoft.com/en-us/library/6c3yckfw(v=vs.100).aspx
<asp:TemplateField HeaderText="Company" ItemStyle-Width="20%" >
<ItemTemplate>
<asp:HyperLink Text='<%# (Eval("Company"))%>' ID="HyperLink1" Target="_blank" runat="server"
NavigateUrl='<%# GetCompanyUrl(Eval("Company"))%>'/>
</ItemTemplate>
</asp:TemplateField>
protected string GetCompanyUrl (object companyNum)
{
return "./NewPageName.aspx?companyId=" + companyNum.ToString();
}
I am trying to get an image to display on a page using a Hyperlink inside a datalist.However, the image will not display, I just get the correct number of boxes with what I call the no image picture. I know that it is retrieving the filepath correctly. The tooltip shows the correct path, it is the exact path going into a repeater that works, but does not display the image. Any help would be greatly appreciated.
<%# Control Language="C#" AutoEventWireup="true" CodeFile="HomePagePhotosList.ascx.cs" Inherits="UserControls_HomePagePhotosList" %>
<asp:DataList ID="list" runat="server" Width="1000px" CssClass="EventsList"
RepeatDirection="Horizontal">
<HeaderStyle CssClass="DepartmentsListHead" />
<HeaderTemplate>
</HeaderTemplate>
<ItemTemplate>
<asp:HyperLink
ID="HyperLink1"
Runat="server"
ImageUrl='<%#System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
NavigateUrl='<%# Link.ToEditMinutesAdmin(Eval("ImageID").ToString())%>'
ToolTip='<%# System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'>
</asp:HyperLink>
</ItemTemplate>
</asp:DataList>
In order to fix this problem I had to change the
ImageUrl='<%#System.String.Format("Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
To
ImageUrl='<%#System.String.Format("~/Images/{0}", DataBinder.Eval(Container.DataItem, "Filepath")) %>'
I have a bound field in my Gridview which is getting its value from a database table.
I have got the data but don't know how to format it inside the gridview.
For example I get total data from below like "123456", but I want to display as "123,456"
<asp:BoundField DataField="totaldata" HeaderText="Total Data"
ReadOnly="True" SortExpression="totaldata" />
How can I do this? Do I need to convert the bound field into a template field ? But what do i do after that.
please help.
I have used DataFormatString="{0:n0}" and it solved the above problem.
how do i do for this:
<asp:TemplateField HeaderText="Failed Files"
SortExpression="NumFailed">
<ItemTemplate>
<asp:Image ID="Image2" runat="server" ImageUrl="~/NewFolder1/warning_16x16.gif" />
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "GetFilesFailed.aspx?id="+Eval("MachineID") %>' Text='<%# Bind("NumFailedFiles") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
the hyperlink has the number which need to be formatted...
Use DataFormat property :
<asp:BoundField DataField="totaldata" HeaderText="Total Data"
ReadOnly="True" SortExpression="totaldata" DataFormatString="{0:n3}" />
EDIT : For the second part of your question use Eval method's second parameter to format your data :
<%# Eval("NumFailedFiles", "{0:n3}") %>
Then your template will be like that :
<asp:TemplateField HeaderText="Failed Files"
SortExpression="NumFailed">
<ItemTemplate>
<asp:Image ID="Image2" runat="server"
ImageUrl="~/NewFolder1/warning_16x16.gif" />
<asp:HyperLink ID="HyperLink1" runat="server"
NavigateUrl='<%# "GetFilesFailed.aspx?id="+Eval("MachineID") %>'
Text='<%# Eval("NumFailedFiles", "{0:n3}") %>'></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
A couple of ways in how you can do that
Option 1
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "GetFilesFailed.aspx?id="+Eval("MachineID") %>' Text='<%# Bind("NumFailedFiles","{0:n0}") %>'></asp:HyperLink>
Option 2
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "GetFilesFailed.aspx? id="+Eval("MachineID") %>' Text='<%# Bind("NumFailedFiles").ToString("N") %>'></asp:HyperLink>
Option 3
Create a method in the code behind page that returns the formatted number.
protected string GetFormatedNumber(object number)
{
if ( number != null )
{
return number.ToString("N");
}
return "0";
}
And call the method in your aspx page as below:
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# "GetFilesFailed.aspx? id="+Eval("MachineID") %>' Text='<%#GetFormatedNumber(Eval("NumFailedFiles")) %>'></asp:HyperLink>
I think you need to take a look at this MSDN article on How to Format Data in the DataGridView
if you want to format your data on gridview use "{0:n3}"
<asp:Label ID="label" runat="server" Visible="true" Text='<%#DataBinder.Eval(Container.DataItem, "data","{0:n3}") %>'></asp:Label>