Tuesday, June 26, 2012

hyperlink in template column gridview

following snippet is useful to insert hyperlink template column in grdview 

    <asp:TemplateField  HeaderText="User name">
                    <asp:HyperLink runat="server" ID="lnkRedirect"  NavigateUrl='<%# String.Format("~/UserDetails.aspx?username={0}",Container.DataItem) %>' Text='<%# Container.DataItem %>'></asp:HyperLink>

if you are binding arraylist to gridview & grdview contains template column then in controls text property
use Text='<%# Container.DataItem %>' instead of Text='<%# ColumnName %>' because columnName is not available in arraylist

No comments:

Post a Comment