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();
}
Related
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")
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 importing a column in datatable to my grid. Now I want navigate to a new page on selecting a cell in grid by fetching the selected value. I have tried this by including bound field in my grid like
<asp:GridView ID="GDV_1" runat="server" EnableModelValidation="true" AutoGenerateColumns="false" OnSelectedIndexChanged="GDV_1_SelectedIndexChanged" AutoGenerateSelectButton="false" DataKeyNames="SROID">
<Columns>
<asp:BoundField DataField="SRONameinEnglish" HtmlEncode="False" DataFormatString="<a target='_blank' href='Test.aspx?code={0}>ClickHere</a>" />
</Columns>
</asp:GridView>
Doing this way my requirement is achieved but the all cells are displaying Common text Click here instead of showing data from Database.
Please give your suggestion on how to get the value from database into cell and make it clickable. I don't want to use Select button. Please find my current output.
This is my current output I want my data from DB instead of ClickHere.
You can use TemplateField
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:LinkButton runat="server" ID="lnk<%# Eval("SRONameinEnglish")%>"><%# Eval("SRONameinEnglish")%></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
and click of LinkButton put your code to navigate anywhere.
In your case you are binding boundfield with static a tag which have href attribute so your not able to change text on that boundfield from your database.To get your approach you should
use TemplateField and bind data with text attribute using eval keyword as below example.
Try it:
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" Text='<%# Eval("name") %>' />
</ItemTemplate>
</asp:TemplateField>
OR
you can also bind link with your hyperlink using NavigateUrl property of hyperlink as below example.
<asp:TemplateField HeaderText="Name">
<ItemTemplate>
<asp:HyperLink id="HyperLink2" NavigateUrl='<%#Eval("YourUrl") %>' Text='<%#Eval("name") %>' runat="server"/>
</ItemTemplate>
</asp:TemplateField>
I hope it will helpful to you.
Ok, this should be really easy, but I just don't have enough experience.
I need to throw a GridView on a WebForm and populate with a List, where Template is my class that has ID, Name, CreatedOn, etc... properties.
The GridView needs to display each Template Name as a link. The link should point to TemplateEdit.aspx page, with the following URL: TemplateEdit.aspx?ID={ID of Template}.
I also need a Delete link (preferably an image link), that should popup a Yes/No delete confirmation dialog.
I've actually done this before in 2005 or so, but I simply can't remember anymore.
Here's how you do it (borrowed the code from here to save some typing)
<asp:TemplateField HeaderText="Statement" SortExpression="Statement">
<ItemTemplate>
<asp:HyperLink ID="Link1" runat="server" NavigateUrl='<%# Bind("ID", "~/TemplateEdit.aspx?ID={0}") %>' Text="The Best Link"></asp:HyperLink >
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<asp:ImageButton ID="DeleteButton" Runat="server" ImageUrl="~/images/delete.gif" OnClientClick="return confirm('Are you sure you want to delete this?');" ToolTip="Delete" CommandName="Delete" />
</ItemTemplate>
</asp:TemplateField>
didn't actually test it, but looks like it should work.
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>