I'm trying to retrieve a URL parameter and pass it into a HyperLinkField inside my GridView.
The URL looks like http://application.com/dynamic.aspx?locale=us. I need to pull the value of the locale param and include it in the asp:HyperLinkField. I know that I can retrieve this param in the code behind like this:
Request.QueryString["locale"].ToString()
But is it possible to retrieve this value inside the .aspx?
<asp:HyperLinkField DataTextField="ref_id" DataNavigateUrlFields="???,ref_id" DataNavigateUrlFormatString="dynamic.aspx?locale={0}&id={1}" Text="ID" HeaderText="ID" SortExpression="ref_id" >
Better switch to a TemplateField. You have much more control that way.
<asp:TemplateField HeaderText="ID">
<ItemTemplate>
<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# string.Format("/dynamic.aspx?locale={0}&id={1}", Request.QueryString["locale"], Eval("ref_id")) %>'><%# Eval("ref_id") %></asp:HyperLink>
</ItemTemplate>
</asp:TemplateField>
Related
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.
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 using the standard GridView.
I have this part working so far.
<asp:HyperLinkField ShowHeader="true" DataTextField="id" DataNavigateUrlFields="id"
DataNavigateUrlFormatString="edit.aspx?id={0}"
DataTextFormatString="Edit" />
However each page needs a 'number' and a 'userid' parameter.
I cannot figure out how to add these parameters to the above HyperLinkField.
<asp:HyperLinkField ShowHeader="true" DataTextField="id"
DataNavigateUrlFields="id"DataNavigateUrlFormatString="edit.aspx?id={0}
&number=Request.QueryString["number"]&
userid=Request.QueryString["userid"]" DataTextFormatString="Edit" />
Can someone tell me what I am missing to be able to add this custom URL to my HyperLinkField?
Try using a templatefield, something like (untested):
<asp:TemplateField HeaderText="Edit">
<ItemTemplate>
<a href='<%# "edit.aspx?id="+Eval("id") + "&number=" +Request.QueryString["number"]+"&userid=" +Request.QueryString["userid"] %>'>Edit</a>
</ItemTemplate>
</asp:TemplateField>
Here is the code:
<asp:DataGrid id="dataGrid1" runat="server" OnItemDataBound="dataGrid1_ItemDataBound">
<Columns>
<asp:HyperLinkColumn DataNavigateUrlFields="Valid,CouponCode"
DataTextField="Valid"
HeaderText="Enable / Disable"
DataNavigateUrlFormatString="?id={0}orgValue={1}" />
</Columns>
</asp:DataGrid>
In newer version of .net they got DataNavigateUrlFields, but in asp.net only have DataNavigateUrlField. (Ref: http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.hyperlinkfield.datanavigateurlfields(v=vs.80).aspx)
So, how can I pass two value into HyperLinkColumn? Thanks.
If you need to pass multiple parameters then convert that column to itemtemplate hyperlink column and then pass multiple parameters using navigateURL property. Like
<asp:datagrid id="dataGrid1" runat="server" AutoGenerateColumns="False" >
<Columns>
<asp:TemplateColumn HeaderText="Order">
<ItemTemplate>
<asp:Hyperlink runat= "server" Text='<%# DataBinder.Eval(Container.DataItem,"ProductName").tostring%>'
NavigateUrl='<%# "page2.aspx?Name=" & DataBinder.Eval (Container.DataItem,"ProductName").tostring & _
"&ProductID=" & DataBinder.Eval(Container.DataItem,"ProductID").tostring %>' ID="ProductName"/>
</ItemTemplate>
</asp:TemplateColumn>
</Columns>
</asp:datagrid>
You have to do something like that,Hope it works..