Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB7
Expertise: Intermediate
Feb 24, 2003

Creating DataGrid's hyperlink columns with multiple parameters in the Url

The DataGrid's HyperLinkColumn column is great to have a column with an hyperlink that points to an Url with a parameter whose value is taken from the data source, but what if you need to build the target Url with more than one parameter taken from the data source? In this case you can use a template column as follows:

<TemplateColumn>
    <ItemTemplate>
       <asp:HyperLink Runat="server" NavigateUrl='<%# _
          "Details.aspx?EmployeeID=" & Container.DataItem("ID") & _
          "&EmployeeName=" & Container.DataItem("FirstName") %>' />
    </ItemTemplate>
</TemplateColumn>

Instead of doing the string concatenation yourself you can use the BuildUrlWithQueryString function, which must be declared with Public/Protected visibility in the code-behind, as follows:

<TemplateColumn>
    <ItemTemplate>
      <asp:HyperLink Runat="server" NavigateUrl='<%# _
         BuildUrlWithQueryString("Details.aspx", _
         "EmployeeID", Container.DataItem("ID"),
         "EmployeeName", Container.DataItem("FirstName")) %>' />
   </ItemTemplate>
</TemplateColumn>

Marco Bellinaso
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap