Click here to Skip to main content
15,895,656 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
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
XML
<%@ 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
Comments
I.explore.code 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

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(<bytes>) 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.
 
Share this answer
 
Comments
rocksean30 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">
<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
I.explore.code 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 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.
I.explore.code 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 24-Aug-12 7:10am    
I want to load the images in separate div tags.
How can i do that ?

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