Click here to Skip to main content
15,936,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to make a photo gallery. But I have a problem to show the image in the list view. and images are stored in the database(SQL Server 2005).
I want to show image in a table format and if I click on any image, this will open into a new window with a big size. I am using a listView But it didn't work properly. Can I use another control to show image?
Updated 8-Jul-20 1:58am

You can even use GridView Control to achieve the same as it has lot of features.

First, Place the GridView in your main page as follows:
(Replace <Put-Your-DataSet-ImageURL-FieldName> by your actual field name)

    <form id="frmGallery" runat="server">
        <table id="Table6" align="center" cellpadding="0" cellspacing="0" style="border: 0px Solid Gray;
            width: 100%; font-family: tahoma; font-size: 10pt; background-color: white;">
                <td style="width: 100%; height: 200px;" align="left" valign="top">
                    <asp:GridView ID="gvImageGallery" runat="server"
                        PageSize="50" AutoGenerateColumns="false" Width="100%"
                            <asp:TemplateField HeaderText="Image">
                                <ItemStyle Width="100%" />
                                    <asp:ImageButton ID="imgBtnShow" runat="server" CommandName="ShowImage" CommandArgument="<%# Container.DataItemIndex %>"
                                        ImageUrl="<Put-Your-DataSet-ImageURL-FieldName>" />

Bind your GridView with your DataSet and add the Event " gvImageGallery_RowCommand "

In this event, first find the selected row-index, then find the ImageButton control and finally get the ImageURL of this Button.

Add ClientScript to open the Popup window to show the Image(You need to create the page before that)
(find sample below)

private void BindGridView()
    DataSet ds = "your-dataset-retrieval-stuff-here";

    gvImageGallery.DataSource = ds;

protected void gvImageGallery_RowCommand(object sender, GridViewCommandEventArgs e)
    if (e.CommandName == "ShowImage")
	// Get Selected Row Index through CommandArgument
	int index = Convert.ToInt32(e.CommandArgument);

	// Find ImageButton in GridView Row
	ImageButton imgBtn = (ImageButton)gvImageGallery.Rows[index].Cells[0].FindControl("imgBtnShow");

	// Get Selected Image's URL
	string imageURL = imgBtn.ImageUrl;

	// Open Popup window
	ClientScript.RegisterStartupScript(this.GetType(), "show", "<script language="javascript">'Pop.aspx?URL=" + imageURL + "','ShowImage','height=300px,width=600px,scrollbars=1,center=yes');</script>");

In your pop-up window Create a Image and Set ImageURL from QueryString value(sample mentioned below)

    <form id="frmPopup" runat="server">
     <asp:Image ID="imgShow" runat="server" />

public partial class Pop : System.Web.UI.Page
	protected void Page_Load(object sender, EventArgs e)
	    if (!IsPostBack)
		if (Request.QueryString["URL"] != null)
		    imgShow.ImageUrl = Request.QueryString["URL"];

Finally make the styles of GridView, ImageButton and Popup window height and width as per your requirements
Share this answer
Sandeep Mewara 7-Apr-11 10:36am    
My 5!
Tarun.K.S 7-Apr-11 10:47am    
Good answer! have a 5!

Take Image Control in listview Itemtemplate
<asp:ImageButton ID="ImageButton1" runat="server"
ImageUrl="~/Admin/Images/cross.gif"  />
br mode="hold" />
also set width and height of Image as your Requirement

and OnClientClick Write your function to pop a window and display Full Image
Share this answer
this link help you to solve your issue
Image Handling In ASP.NET[^]
Share this answer
Mydsh 9-Aug-12 1:43am    
I want to bind images horizontally in listview how to do it using c#
raju melveetilpurayil 9-Aug-12 4:55am    
check this link, if you want to do "ListView repeat items horizontally"

Mydsh 9-Aug-12 5:06am    
Thank You
raju melveetilpurayil 9-Aug-12 5:49am    
Always welcome

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900