HyperLink in GridView
I have a gridview set up that contains information about accommodation. Each row then has a link to view more information. On that page information about that accommodation is displayed with a further link to view comments based on the accommodationid. When view开发者_开发技巧ing those comments I want a way to go back to the accommodation viewed without just clicking the back button on the browser.
So basically I need a hyperlink that looks at the accommodation ID wither from the url or the detailsview shown and goes to something like this sort of link where the ID changes depending on what accommodation your viewing:
http://localhost:9000/WebSite1/comments.aspx?Accom_ID=1001
Any ideas how?
Update: Thanks for the responses but I want a link at the bottom of the page not on each row of the gridview. Also the page changes based on what is show so I cant just put a hyperlink to ...accom_id=1001 as sometimes its another ID.
<GidView runat="server">
..
<HyperLinkField Text="Comments" DataNavigateUrlFormatString="~/Comments.aspx?id={0}" DataNavigateUrlFields="ID" />
</GidView>
<asp:HyperLink runat="server" ID="urlComments" Text="Comments" />
and
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
urlComments.NavigateUrl = String.Format("~/Comments.aspx?id={0}", this.Request.QueryString["Accom_ID"]);
}
If you are on page /WebSite1/comments.aspx?Accom_ID=1001
, then just set the hyperlink URL to /WebSite1/accomodation.aspx?Accom_ID=1001
This is how the NavigateURL should be set:
protected override void Page_Load(object sender, EventArgs e)
{
urlComments.NavigateUrl = "~/accomodation.aspx?Accom_ID=" + Request.QueryString["Accom_ID"];
}
精彩评论