Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pass a variable into a HyperlinkField along with a value from a table.

Status
Not open for further replies.

Quickfix99

Technical User
May 16, 2007
27
CA
I am having trouble getting the syntax correct for passing a variable into a URL from a Hyperlink field.

I have a string variable named MAPIMAGE. I would like to pass it to the URL after the "IMAGE=" section, then, get the next paramater from a table value.

How can I do this?

DataNavigateUrlFormatString="~/PropInfo.aspx?IMAGE=MAPIMAGE&PID={0}"

I would like the URL to look like this:


Thanks in advance,

QF
 
Try..
Code:
DataNavigateUrlFormatString='~/PropInfo.aspx?IMAGE=<%=MAPIMAGE%>&PID={0}'
 
Can you post your code so I can look at it and complete it the right way for you?

Thanks :)
 
If the Hyperlink is part of a data control, you can also use it's data bound event, get a reference to the Hyperlink and then set it's NavigateURL in code.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Mark,

That is exactly what I was going to help out with :) If needed, of course.
 
I converted to a template field but am still getting an error. Any ideas?

<asp:TemplateField>
<ItemTemplate>

<asp:HyperLink ID="HyperLink1" runat="server" NavigateUrl='<%# Eval("PID", "~/PropInfo.aspx?PID={0}") + "&Image=" + Eval("MAPIMAGE") %>'

Text='<%# Eval("MSLINK") %>'></asp:HyperLink>

</ItemTemplate>

</asp:TemplateField>

ERROR: DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MAPIMAGE'.
 
NavigateUrl='<%# "~/PropInfo.aspx?PID=" + Eval("PID") + "&Image=" + Eval("MAPIMAGE") %>'


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Still get this error:

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'MAPIMAGE'.

MAPIMAGE is a variable set from a querystring. I need to pass this variable into the NavigateURLString.
 
ok, that make all the difference.
NavigateUrl='<%# "~/PropInfo.aspx?PID=" + Eval("PID") + "&Image=" + Request.QueryString["MAPIMAGE"] %>'


Jason Meckley
Programmer
Specialty Bakers, Inc.
 
the url is encoded so & is converted to &amp; look for an htmlencode t/f property on the template column or something like that to disable encoding.

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Yikes...it appears that the HtmlEncode propety is not available for a template field! It looks like I am going to have to get creative with this and write some code-behind or something...Any ideas?
 
Tried this, but didn't work either:

NavigateUrl='<%# Server.HtmlEncode("~/PropInfo.aspx?PID=" + Eval("PID") + "&Image=" + Request.QueryString["MAPIMAGE"]) %>'

Results in:


I can't believe such a simple request has stumped everyone. I wonder if this could be considered a bug?
 
As tperri stated, use the RowDataBoundEvent in the codebehind. Get a reference to the hyperink using FindControl(). Then set the NavigateURL property there.
 
I can't believe such a simple request has stumped everyone. I wonder if this could be considered a bug?
Nope it's not a bug, and if search google for HTMLEncode you would will find the simple answer in a matter of seconds.


-------------------------------------------------------

Mark,
[URL unfurl="true"]http://aspnetlibrary.com[/url]
[URL unfurl="true"]http://mdssolutions.co.uk[/url] - Delivering professional ASP.NET solutions
[URL unfurl="true"]http://weblogs.asp.net/marksmith[/url]
 
Code:
      <asp:gridview id="CustomersGridView" 
        onrowdatabound="CustomersGridView_RowDataBound" 
        runat="server">
      </asp:gridview>

Keep NavigateUrl='<%# "~/PropInfo.aspx?PID=" + Eval("PID") + "&Image=" + Request.QueryString["MAPIMAGE"] %>' in your template column.


Code:
  void CustomersGridView_RowDataBound(Object sender, GridViewRowEventArgs e)
  {

    if(e.Row.RowType == DataControlRowType.DataRow)
    {
         Hyperlink hl = (Hyperlink)e.Rows.FindControl("Hyperlink1");

      hl.NavigateURL = Server.UrlEncode(hl.NavigateURL);
      

    }

  }

Untested.

google: ASP.Net Gridview RowDataBound.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top