Hi shivavidhyadhar,
Refer below sample.
HTML
<asp:GridView ID="gvCustomers" runat="server" AutoGenerateColumns="false" OnRowCommand="OnRowCommand">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" />
<asp:BoundField DataField="Name" HeaderText="Name" />
<asp:TemplateField HeaderText="Photo">
<ItemTemplate>
<asp:Image ID="imgPhoto" runat="server" ImageUrl='<%# Eval("Photo") %>' Height="100"
Width="100" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Action">
<ItemTemplate>
<asp:LinkButton ID="btnView" Text="View" runat="server" CommandName="View"
CommandArgument="<%# Container.DataItemIndex %>"></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
<hr />
<asp:Image ID="imgPhoto" runat="server" Height="200" Width="200" Visible="false" />
Namespaces
C#
using System.Data;
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
DataTable dt = new DataTable();
dt.Columns.AddRange(new DataColumn[3] { new DataColumn("Id"), new DataColumn("Name"), new DataColumn("Photo") });
dt.Rows.Add(1, "LightHouse", "Lighthouse.jpg");
dt.Rows.Add(2, "Tulips", "Tulips.jpg");
gvCustomers.DataSource = dt;
gvCustomers.DataBind();
}
}
protected void OnRowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "View")
{
int rowIndex = Convert.ToInt32(e.CommandArgument);
GridViewRow row = gvCustomers.Rows[rowIndex];
Image img = (Image)row.FindControl("imgPhoto");
imgPhoto.ImageUrl = img.ImageUrl;
imgPhoto.Visible = true;
}
}
Screenshot