Click here to Skip to main content
15,905,322 members

Comments by rocksean30 (Top 3 by date)

rocksean30 24-Aug-12 7:10am View    
I want to load the images in separate div tags.
How can i do that ?
rocksean30 24-Aug-12 7:04am View    
lol half of the comment is lost!!
I appreciate your fast reply @gladiatron
Thanks
Please give me links which would help me in this project.
rocksean30 24-Aug-12 7:00am View    
I know how to insert images in a grid view from database.
Default2.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head id="Head1" runat="server">
<title>Inserting images into databse and displaying images with gridview</title>
<style type="text/css">
.Gridview
{
font-family:Verdana;
font-size:10pt;
font-weight:normal;
color:black;
width:500px;
}
</style>
</head>

<body>
<form id="form1" runat="server">
<div>
<table>
<tr>
<td>
Image Name:
</td>
<td>
<asp:TextBox ID="txtImageName" runat="server">
</td>
</tr>
<tr>
<td>
Upload Image:
</td>
<td>
<asp:FileUpload ID="fileuploadImage" runat="server" />
</td>
</tr>
<tr>
<td>
</td>
<td>
<asp:Button ID="btnUpload" runat="server" Text="Upload" onclick="btnUpload_Click" />
</td>
</tr>
</table>
</div>
<div>
<asp:GridView ID="gvImages" CssClass="Gridview" runat="server" AutoGenerateColumns="False"
HeaderStyle-BackColor="#7779AF" HeaderStyle-ForeColor="white"
BackColor="White" BorderColor="#999999" BorderStyle="Solid" BorderWidth="1px"
CellPadding="3" ForeColor="Black" GridLines="Vertical" Width="100%"
onrowdeleting="gvImages_RowDeleting" onrowediting="gvImages_RowEditing">
<columns>
<asp:BoundField HeaderText = "Image Name" DataField="imagename"/>
<asp:TemplateField HeaderText="Image">
<itemtemplate>
<asp:Image ID="Image1" runat="server" ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("ImageID") %>' Height="300" Width="300" />


<asp:CommandField ShowDeleteButton="True" ShowEditButton="True" />

<footerstyle backcolor="#CCCCCC">
<PagerStyle BackColor="#999999" ForeColor="Black" HorizontalAlign="Center" />
<SelectedRowStyle BackColor="#000099" Font-Bold="True" ForeColor="White" />

<HeaderStyle BackColor="Black" ForeColor="White" Font-Bold="True"></HeaderStyle>
<alternatingrowstyle backcolor="#CCCCCC">

</div>
</form>
</body>

</html>

ImageHandler.ashx
<%@ WebHandler Language="C#" Class="ImageHandler" %>

using System;
using System.Web;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public class ImageHandler : IHttpHandler {

string strcon = ConfigurationManager.ConnectionStrings["dbconnection"].ConnectionString;

public void ProcessRequest(HttpContext context)
{
string imageid = context.Request.QueryString["ImID"];
SqlConnection connection = new SqlConnection(strcon);
connection.Open();
SqlCommand command = new SqlCommand("select Image from mypics where ImageID=" + imageid, connection);
SqlDataReader dr = command.Execu