Ajit N

Ajit N

  • NA
  • 352
  • 71.5k

How to Show Image in new Tab on gridview image button click?

Jun 29 2019 10:35 PM
Hello, I want to show image in new tab when i click on particular image button in GridView. i tried some code which i mentioned below,but it didn't work for me. so help me how can i do this.
 
Front End Code
  1. <asp:GridView ID="GridView1" runat="server" CssClass="table table-bordered table-hover" DataKeyNames="ID" OnRowCommand="GridView1_RowCommand" OnSelectedIndexChanged="GridView1_SelectedIndexChanged" EmptyDataText="No records has been added." AutoGenerateColumns="False">  
  2. <Columns>  
  3. <asp:BoundField DataField="ID" HeaderText="ID" />  
  4. <asp:TemplateField HeaderText="Photo">  
  5. <ItemTemplate>  
  6. <asp:ImageButton ID="imgRedirect" runat="server" Height="50px" Width="50px" ImageUrl='<%# Eval("img") %>' OnClick="imgRedirect_Click" />  
  7. </ItemTemplate>  
  8. </asp:TemplateField>  
  9. </Columns>  
  10. </asp:GridView>  
Backend Code
  1. protected void imgRedirect_Click(object sender, ImageClickEventArgs e)  
  2. {  
  3. int getid = Convert.ToInt32(GridView1.Rows[GridView1.SelectedIndex].Cells[0].Text);  
  4. string imagename = string.Empty;  
  5. con.Open();  
  6. SqlCommand cmd = new SqlCommand("select * from AddPrescription where ID='"+ getid + "'", con);  
  7. SqlDataReader dr = cmd.ExecuteReader();  
  8. if (dr.Read())  
  9. {  
  10. imagename = dr["img"].ToString();  
  11. }  
  12. con.Close();  
  13. Response.Redirect(imagename);  
  14. }  

Answers (2)