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