Wednesday, September 23, 2009

HyperLinkField in GridView with multiple fields does not work

<asp:GridView ID="GV" runat="server" AutoGenerateColumns="False">


<Columns>    


<asp:HyperLinkField DataNavigateUrlFields="CAM,Floor,Riser" DataNavigateUrlFormatString="HorzHandover.aspx?CAM={0}&amp;Floor={1}&amp;Riser={2}"     Text="Handover"/>     


 


<asp:TemplateField>        


    <ItemTemplate>            


    <asp:HyperLink ID="HyperLink1" runat="server"  NavigateUrl='<%# "Export.aspx?CAM="+Eval("CAM")+"&Floor="+Eval("Floor")+"&Riser="+Eval("Riser") %>' Text="Signoff"></asp:HyperLink>            </ItemTemplate>


</asp:TemplateField>


</Columns>


</asp:GridView>





I think this is a bug in asp.net. HyperLinkField in GridViews with multiple fields do not seem to work at all. You have to turn column into a template to make it work (as shown above)

1 comment:

EB said...

What I found is that I was abloe to get the HyperLinkField working in the GridView with two fields if both were an integer value. But one of the fields I want to use is a time stamp, so I think the slashes or colon or spaces may have been causing it to fail. But I used your method and that did the trick! Thanks!

Eric