Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET SQL-Server
Hi friends,
I am creating a web site which consist of games from different platforms and display information about it and registered users can comment on games.
So i need to create a page game.aspx?id='int value' and this page will contain picture of the game, title, description which is retrieved from sql server 2005.
Please help me I need to submit this project tomorrow.
 
In platforms page ill post games like in pc.aspx
<%@ Page Language="C#" MasterPageFile="~/MasterPage.master" AutoEventWireup="true" CodeFile="pc.aspx.cs" Inherits="pc" Title="Untitled Page" %>
 
<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder_main" Runat="Server">
    <div class="block">
        <div class="block-bot">
          <div class="head">
            <div class="head-cnt">
              <h3>PC Games</h3>
              <div class="cl">&nbsp;</div>
            </div>
          </div>
          <div class="col-articles articles">
            <div class="cl">&nbsp;</div>
 
            <div class="article">
              <div class="image">
              <a href="game.aspx">
                <img src="App_Themes/Theme1/css/images/img4.jpg" alt="" />
              </a>
              </div>
              <h4><a href="#">F.E.A.R.2</a></h4>
              <p><strong>PC</strong></p>
            </div>
 
            <div class="cl">&nbsp;</div>
          </div>
        </div>
    </div>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="image_articles_games" Runat="Server">
</asp:Content>
 
for now i have loaded the pics from images folder in the server but I want to load images and other information from sql server 2005
 
and in game.aspx page i want to display the game pics, title, description, ratings, comments from database
 
Please help asap....
Regards
Posted 24-Aug-12 1:15am
Comments
gladiatron at 24-Aug-12 6:41am
   
you really think getting a help on such short notice is possible in a non-real time platform like CP?? your best bet (only because of the time crunch) would be to get hold of a friend from your neighbourhood or class and work it out.

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

on the flip side, this is one thing you can try. Store Image as bytes in the SQL server (think its blob type in SQL server 2005) and then create an HttpHandler to read the contents of that Image column and then do a Response.Write() from the handler to render the image on the page. The image tag's src would be the path of the handler file appended with a querystring say id=1, to fetch an image corresponding to a certain id.
 
See if this helps you.
  Permalink  
Comments
rocksean30 at 24-Aug-12 7:00am
   
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">

<asp:BoundField HeaderText = "Image Name" DataField="imagename"/>
<asp:TemplateField HeaderText="Image">

<asp:Image ID="Image1" runat="server" ImageUrl='<%# "ImageHandler.ashx?ImID="+ Eval("ImageID") %>' Height="300" Width="300" />


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


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


</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
gladiatron at 24-Aug-12 7:06am
   
You went over the limit for a comment because you decided to dump your code in the comment, which should have gone into where your question is. Now what is your question then?
rocksean30 at 24-Aug-12 7:04am
   
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.
gladiatron at 24-Aug-12 7:08am
   
I don't have any links specific to your problem, what i suggested is something what I would do. If you can show the images in the gridview surely u can extend that logic to showing images anywhere in the website.
rocksean30 at 24-Aug-12 7:10am
   
I want to load the images in separate div tags.
How can i do that ?
gladiatron at 24-Aug-12 7:13am
   
i think if you use <asp:Panel> tag then you can use the same logic as your GridView to render images in there (using an <asp:Image> inside the panel), because the asp:Panel effectively gets renderd as a div on the browser.

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

  Print Answers RSS
0 OriginalGriff 190
1 Jochen Arndt 155
2 PIEBALDconsult 150
3 Afzaal Ahmad Zeeshan 120
4 DamithSL 115
0 OriginalGriff 5,695
1 DamithSL 4,591
2 Maciej Los 4,012
3 Kornfeld Eliyahu Peter 3,480
4 Sergey Alexandrovich Kryukov 3,190


Advertise | Privacy | Mobile
Web02 | 2.8.141220.1 | Last Updated 24 Aug 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100