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 dencom on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

HyperLinkField not executing code render block 1

Status
Not open for further replies.

mais123

Programmer
Dec 26, 2007
36
US
I have a GridView where I use HyperlinkField. The thing is I need to encrypt the userID I put into the query string so I am trying to call code render Encrypt function to encrypt. But the problem is that Encrypt never gets executed. What is wrong:. Here is my code:

Code:
 <asp:HyperLinkField DataNavigateUrlFields="Id"  DataNavigateUrlFormatString="EnterCustomer.aspx?CustomerID=<%= Encode({0}) %>"
                 DataTextField="CompanyName" HeaderText="Customer Name" Text="Name"   />
 
Code:
 <asp:HyperLinkField 
   NavigateUrl='<%="EnterCustomer.aspx?CustomerID="  + Encode(Eval("Id")) %>'
   DataTextField="CompanyName" 
   HeaderText="Customer Name" />
if that doesn't work use a template column with a hyperlink object and set the ItemDataBound event for the grid view, then set the navigate url property for each row. something like this
Code:
<asp:GridView ... OnRowDataBound="GridView_ItemDataBound">
   <Columns>
      <asp:TemplateColumn headertext="Company Name">
         <asp:Hyperlink id="Link" runat="server" />
      </asp:TemplateColumn>
   </Columns>
</asp:GridView>
Code:
protected void GridView_ItemDataBound(sender e, GridViewRowEventArgs e)
{
   if (e.Row.RowIndex > -1)
   {
      MyDataObject item = (MyDataObject)e.Row.DataItem;
      Hyperlink link = (Hyperlink)e.Row.FindControl("Link");
      link.NavigateUrl = "EnterCustomer.aspx?CustomerID="  + Encode(item.Id);
      link.Text = item.CompanyName;
   }
}

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top