locked
Making image clickable in gridview imagefield RRS feed

  • Question

  • User-1647172364 posted
    Hlo Sir

    My query is that when i clicked on image in gridview i want it clickable image to its full screen size on mouse click .

    Here is my code


    Aspx
    <%@ Page Title="" Language="C#" MasterPageFile="~/Site1.Master" AutoEventWireup="true" CodeBehind="Test lang.aspx.cs" Inherits="WebApplication14.Test_lang" %> <asp:Content ID="Content1" ContentPlaceHolderID="title" runat="server"> </asp:Content> <asp:Content ID="Content2" ContentPlaceHolderID="head" runat="server"> </asp:Content> <asp:Content ID="Content3" ContentPlaceHolderID="body" runat="server"> <div style="margin-top:30px; margin-left:20px"> <h1><strong style="color:black">Test Language</strong></h1> <hr /> <table> <tr> <td><span style="color:black">First Name</span><br /> <asp:TextBox ID ="tb_name" runat="server" Width="200px" /><br /> </td> <td><span style="margin-left:25px; color:black">Last Name<br /></span> <span style="margin-left:25px"><asp:TextBox ID="tb_last" runat="server" Width="200px" /></span> <br /> </td></tr> <tr> <td> <br /><asp:FileUpload ID="fileupload" runat="server" BackColor="lightblue" /> </td> </tr> <tr> <td><br /> <asp:Button ID="BT_submit" runat="server" Text="Submit" style="border-radius:5px" Height="35px" Width="80px" OnClick="BT_submit_Click" BackColor="#3366CC" BorderColor="#3366CC" ForeColor="White" /></td> </tr> </table> </div> <div style="margin-top:30px; margin-left:50px"> <asp:GridView runat="server" AutoGenerateColumns="false" ID="Gv1" Width="60%" OnPageIndexChanging="Gv1_PageIndexChanging" AllowPaging="true" PageSize="10"> <Columns> <asp:BoundField DataField ="first_name" HeaderText ="First Name" /> <asp:BoundField DataField ="last_Name" HeaderText ="Last Name" /> <asp:ImageField DataImageUrlField="image" HeaderText="Image" ControlStyle-Height="95" ControlStyle-Width="170" ItemStyle-HorizontalAlign="Center"> </asp:ImageField> </Columns> <EditRowStyle BackColor="#2461BF" /> <FooterStyle BackColor="#507CD1" ForeColor="White" Font-Bold="True" /> <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" /> <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" /> <RowStyle BackColor="#EFF3FB" /> <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" /> <SortedAscendingCellStyle BackColor="#F5F7FB" /> <SortedAscendingHeaderStyle BackColor="#6D95E1" /> <SortedDescendingCellStyle BackColor="#E9EBEF" /> <SortedDescendingHeaderStyle BackColor="#4870BE" /> </asp:GridView> </div> </asp:Content> C# using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data; using System.Data.SqlClient; using System.IO; using System.Configuration; namespace WebApplication14 { public partial class Test_lang : System.Web.UI.Page { SqlCommand cmd = new SqlCommand(); SqlConnection con = new SqlConnection(); string connection = System.Configuration.ConfigurationManager.AppSettings["con"].ToString(); public void EstablishConnection(string storeprocedure) { con.ConnectionString = connection; cmd.Connection = con; cmd.Connection.Open(); cmd.CommandType = CommandType.StoredProcedure; cmd.CommandText = storeprocedure; } public void CloseConnection() { cmd.Connection.Close(); cmd.Connection.Dispose(); con.Close(); } public void FillGridview() { SqlDataAdapter adp = new SqlDataAdapter("select * from test_lang", connection); adp.SelectCommand.CommandType = CommandType.Text; DataTable DT = new DataTable(); adp.Fill(DT); Gv1.DataSource = DT; Gv1.DataBind(); } protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { FillGridview(); } } protected void BT_submit_Click(object sender, EventArgs e) { string fileName = Path.GetFileName(fileupload.PostedFile.FileName); string filePath = "~/img/" + fileName; fileupload.PostedFile.SaveAs(Server.MapPath(filePath)); EstablishConnection("sp_insert_test_lang"); cmd.Parameters.Add("@first_name", SqlDbType.NVarChar, 100).Value = tb_name.Text; cmd.Parameters.Add("@last_name", SqlDbType.NVarChar, 100).Value = tb_last.Text; cmd.Parameters.Add("@Remarks", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@date_time", SqlDbType.VarChar, 100).Value = System.DateTime.Now.ToString(); cmd.Parameters.Add("@Status", SqlDbType.VarChar, 100).Value = "1"; cmd.Parameters.Add("@By_whom", SqlDbType.VarChar, 100).Value = Session["username"].ToString(); cmd.Parameters.Add("@image", SqlDbType.VarChar, 100).Value = filePath; try { cmd.ExecuteNonQuery(); } catch (Exception ex1) { Response.Write("<script language=javascript>alert('" + ex1.Message.ToString() + ".')</script>"); } CloseConnection(); FillGridview(); } protected void Gv1_PageIndexChanging(object sender, GridViewPageEventArgs e) { Gv1.PageIndex = e.NewPageIndex; FillGridview(); } } }

    Monday, June 29, 2020 7:51 AM

All replies