Site Search

Thursday, June 30, 2011

How to add image link in to Gridview column

This will add cursor hand when hover on to the image.
.aspx
              <Columns>
                <asp:TemplateField>
                    <HeaderStyle HorizontalAlign="Left" Width="15px" />
                    <ItemTemplate>
                        <asp:HyperLink ID="Image" runat="server" />
                    </ItemTemplate>
                </asp:TemplateField>
            </Columns>
aspx.cs
protected void GridViewRowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {         
                HyperLink rLink = (HyperLink)e.Row.Cells[column index].Controls[1];
                Link.ImageUrl = "image path";
                Link.NavigateUrl = "http://www.google.com";
            }
        }

No comments:

Post a Comment