Monday, December 2, 2013

ASP GridView HyperLink without Code Behind

The following code snippet allows for a hyperlink to be built using the GridView's data source, along with a specified URL format.

<asp:HyperLinkField HeaderText="View Newsletter" DataNavigateUrlFields="Newsletter_Edition" DataNavigateUrlFormatString="/About/Pages/Newsletter.aspx?Edition={0}" Text="View" />
It would appear in the GridViews full source, like follows:
 <asp:GridView ID="gridArchive" runat="server" AutoGenerateColumns="False" Width="800px" CssClass="newsletter">
<Columns>
<asp:BoundField DataField="Title" HeaderText="Title" />
<asp:BoundField DataField="Issue_x0020_Date" HeaderText="Date Published" />
<asp:BoundField DataField="Edition" HeaderText="Edition" />
<asp:HyperLinkField HeaderText="View Newsletter" DataNavigateUrlFields="Edition" DataNavigateUrlFormatString="/About/Pages/Newsletter.aspx?Edition={0}" Text="View" />
</Columns>
</asp:GridView>

No comments:

Post a Comment