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)