INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Jobs

ASP.NET 101

How to pass variables thru a DataGrid hyperlink column by Isadore
Posted: 30 Oct 03 (Edited 22 Sep 04)

On several occassions in the past we have brought up the notion of passing variable(s); as well as redirecting URL's, when using a hyperlink column in a datagrid.  I list the following conditions as a summary of these events, thought they are not all inclusive.

Case 1: Simple single variable transfer...

CODE

<asp:HyperLinkColumn
  HeaderText="Select Site Code"
  DataNavigateURLField="AwwSiteCode"
  DataNavigateUrlFormatString="ChemRT.aspx?AwwCode={0}"
DataTextField="AwwSiteCode"
/>
In this case, the first grid column, (0), is redirected to the page ChemRT.aspx as a QueryString.

Case 2: More than one variable in Grid...

CODE

<asp:TemplateColumn HeaderText="Select Site">
 <ItemTemplate>
  <asp:HyperLink
   id=HyperLink1
   runat="server"
   Text='<%# DataBinder.Eval(Container,DataItem.AWWCode")%>'
   NavigateUrl='<%# "ChemOT.aspx?AwwCode=" & DataBinder.Eval(Container, "DataItem.AWWCode")& "&GroupName=" & DataBinder.Eval(Container, "DataItem.Group_Name")%>'
/>
</ItemTemplate>
</asp:TemplateColumn>
In this case a Templace Column is used, and one can transfer one, or all field values for the row selected.

Case 3. Sending grid variable + QueryString...

CODE

<asp:TemplateColumn HeaderText="Select Site">
 <ItemTemplate>
  <asp:HyperLink
   id=HyperLink1
   runat="server"
   Text='<%# DataBinder.Eval(Container, "DataItem.AWWCode")%>'
   NavigateUrl='<%# "SiteChemHistory.aspx?AwwCode=" & DataBinder.Eval(Container, "DataItem.AWWCode") & "&ChartID=" & Request.QueryString("ChartID")%>'
/>
</ItemTemplate>
</asp:TemplateColumn>
Case 4.  Changing the URL redirect page...

   In this case, a Querystring value is needed on the page with the grid.  Acoording to this value, one needs to change the redirect page as well as past variables.

 In the code behind on the page load event put:

CODE

Dim strURL As String
If Request.QueryString("ID") = 1 Then
 strURL = "ddChemHistory.aspx?AwwSiteCode="
Else
 strURL = "ddPolarHistory.aspx?AwwSiteCode="
End If

Now caputre the redirect page in the grid hyperlink...

<asp:TemplateColumn HeaderText="Select Site">
 <ItemTemplate>
  <asp:HyperLink
   id=HyperLink1
   runat="server"
   HeaderText="Select Site"
   Text='<%# DataBinder.Eval(Container, "DataItem.AWWSiteCode")%>'
NavigateUrl='<%#strURL & DataBinder.Eval(Container, "DataItem.AWWSiteCode") & "ChartID=" & Request.QueryString("ChartID")%>'
   />
 </ItemTemplate>
</asp:TemplateColumn>
In this last case the redirect page, 'strURL', is captured along with the hyperlinked field.  Any combination of grid values of page variables may be sutbstituted as demonstrated.

Related threads at Tek-Tips:

1. Converting local URL to Virtual URL:  Thread855-868372
2. Summing up checked checkboxes in grid and sending to next page: Thread855-907488


Back to Microsoft: ASP.NET FAQ Index
Back to Microsoft: ASP.NET Forum

My Archive

Resources

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close