Blue Theme Orange Theme Green Theme Red Theme
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Home | Forums | ASP.NET 2.0 Tutorials | Web Services | How Do I...? | Class Browser | WPF Quick Starts | Advertise with Us
 | Consulting  
Submit an Article Submit a Blog 
Search :       Advanced Search »
Home » Blogs Home » Blog Detail

GridView image popup using JQuery and asp.net

 by Abhijit barua on Jan 23, 2012

GridView image popup using JQuery and asp.net
Download Files: GridView image popup using JQuery and asp.net.rar
Comments: 0 Views: 1146 Printable Version 
First of all i create one table with three field(id,ImageName,ImagePath). I save image path at database and image at folder. To do these you will required JQuery and CSS file which i mention below.(Download code there you will get jquery and css file).

<link href="css/lightbox.css" rel="stylesheet" type="text/css" media="screen" />

    <script type="text/javascript" src="js/prototype.js"></script>

    <script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>

    <script type="text/javascript" src="js/lightbox.js"></script>


Below i show the design page gridview portion.

 <asp:DataGrid ID="DataGrid1" runat="server" AutoGenerateColumns="False" ShowHeader="true"
        CellPadding="5">
        <Columns>
            <asp:TemplateColumn HeaderText="Photo">
                <ItemTemplate>
                    <a href='<%#GetDetail(DataBinder.Eval(Container.DataItem,"id"))%>' rel="lightbox"
                        title='<%#title(DataBinder.Eval(Container.DataItem,"ImageName"))%>'>
                        <img height="100" width="90" style="border: Solid 1px Black;" src='<%#GetDetail(DataBinder.Eval(Container.DataItem,"id"))%>' />
                    </a>
                </ItemTemplate>
            </asp:TemplateColumn>
        </Columns>
    </asp:DataGrid>

Gridview bind at page load like below

        SqlConnection con = new SqlConnection();
        SqlCommand cmd = new SqlCommand();
        con = new SqlConnection("Data Source=server name;Initial Catalog=database name;Integrated Security=SSPI;");
        cmd.Connection = con;
        cmd.CommandText = "Select * from imagetable";
        con.Open();
        DataGrid1.DataSource = cmd.ExecuteReader();
        DataGrid1.DataBind();
        con.Close();

Now Look at below line through which when gridview image is click it show image at popup.

src='<%#GetDetail(DataBinder.Eval(Container.DataItem,"id"))%>'

I write server side code to get image for respective id, like below and when you click at gridview image it's directly go to server side and check GetDetail().

public string GetDetail(object objEmplayeeId)
    {
        string constr = "Data Source=Subhasish-PC;Initial Catalog=testabhijit;Integrated Security=SSPI;";
        int EmplayeeId = int.Parse(objEmplayeeId.ToString());
        //string path = table.Rows[0]["ImagePath"].ToString();
        string query = "SELECT ImagePath FROM imagetable WHERE id = '" + EmplayeeId  + "'";


        SqlDataAdapter da = new SqlDataAdapter(query, constr);
        DataTable table = new DataTable();
        da.Fill(table);
        string path = table.Rows[0]["ImagePath"].ToString();
        return path;

    }

You can download the code attach with these tutorial. Happy codding.








Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
 
What do you say about this post? Post a comment here
*Title:
*Comment:
 
Comments not available.
Nevron Gauge for SharePoint
Become a Sponsor

 Blogger's Profile
Age: 30
Location:
Title: Developer
Joined: Nov 18, 2011
Education: Masters Degree
 More Blogs from this Blogger
No record available
 Latest Blogs
[Video] OnClose Handler
[Video] Storing and Loading the Window and Toolbar position
The Euclidean Algorithm
Swapping Exe Process
How Exe file is Generated by VS2005 C++ Project?
What is Exe
Header files: Multiple Inclusion problem - Solution B
Header files: Multiple Inclusion problem - Solution A
Header files: Multiple Inclusion problem - Reason
Header files: Multiple Inclusion problem
View all »
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 
Team Foundation Server Hosting
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.