Click here to Skip to main content
Click here to Skip to main content
Articles » Database » Database » General » Downloads
 
Add your own
alternative version

Display/Store and Retrieve Image Data from Database to Gridview, and also on Mouse Over

, 15 Oct 2011
How to Display/Store and Retrieve Image Data from Database to Gridview, and also on mouse over
UserSample.zip
UserSample
~$gemArticle.docx
AlgemArticle.docx
Sample
App_Code
App_Data
Bin
AjaxControlToolkit.dll
AjaxControlToolkit.dll.refresh
Utils.dll
Utils.dll.refresh
Utils.pdb
css
Images
accordionHeaderIcon.png
BlackLoadingBar.gif
btn_delete.gif
btn_edit.gif
Calendar.png
close.gif
Copy of gridheader.gif
del.png
downarrow.gif
excel_icon.gif
gridfooter.gif
gridfooter.JPG
gridheader.gif
headermenu.jpg
headerpanel.jpg
lock.png
loginbg.jpg
LoginPanelBG.png
minniloader.gif
pdf.jpg
print-button.gif
scan.gif
spicture.gif
spicture.jpg
Thumbs.db
txt.png
view.gif
js
arrowdown.gif
arrowup.gif
Members.JPG
Sample (3).suo
Show
Algem_G_Mojedo.jpg
Asds_A_Asdasd.jpg
Firstname_M_Lastname.jpg
Sdfdfsdf_S_Sdfsdf.jpg
Test_T_Test.jpg
Test1_T_Resr1.jpg
Thumbs.db
Zxdzx_Z_Zxzx.jpg
upload
UsersControl
Utils
Utils
bin
Debug
Utils.dll
Utils.pdb
obj
Debug
Refactor
TempPE
Utils.dll
Utils.pdb
Properties
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Text;
using System.Data.SqlClient;
using System.Configuration;
//using Entities;
using System.Data;
using Utils;

public partial class PhotoDetail : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (SessionManager.PageIndex != string.Empty)
            {
                this.hfKeyId.Value = SessionManager.KeyPrimary;
                this.hfPageIndex.Value = SessionManager.PageIndex;
            }
            var qry = Request.QueryString["id"];
            var userId = qry;
            this.lblName.Text = "The XP-Team";
            //this.lblRemarks.Text = firstName + " " + lastName;
            // Display the image from the database
            Image1.ImageUrl = "~/ShowFullSizeImg.ashx?id=" + userId;
            //Get user info
            User user = new User();
            user = GetUserInfo(userId);
            this.lblRemarks.Text = user.FirstName + " " + user.LastName + " " + user.MiddleName.Substring(0, 1);
        }
    }

    private User GetUserInfo(string userId)
    {
        string sqlConnection = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        SqlConnection conn;
        SqlCommand cmd;
        User lst = new User();

        try
        {
            using (conn = new SqlConnection(sqlConnection))
            {
                conn.Open();

                StringBuilder sbQry = new StringBuilder();
                sbQry.Append("select * FROM dbo.[User] where UserId = " + userId);
                using (cmd = new SqlCommand(sbQry.ToString(), conn))
                {
                    cmd.CommandType = CommandType.Text;

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        while (dr.Read())
                        {
                            User temp = new User();
                            temp.UserID = Tools.Tools.IifInt(dr["UserID"]);
                            temp.Username = Tools.Tools.IifStr(dr["Username"]);
                            temp.Password = Tools.Tools.IifStr(dr["Password"]);
                            temp.LastName = Tools.Tools.IifStr(dr["LastName"]);
                            temp.FirstName = Tools.Tools.IifStr(dr["FirstName"]);
                            temp.MiddleName = Tools.Tools.IifStr(dr["MiddleName"]);
                            temp.WorksiteCode = Tools.Tools.IifStr(dr["WorksiteCode"]);
                            temp.AccessLevel = Tools.Tools.IifInt(dr["AccessLevel"]);
                            temp.Active = Tools.Tools.IifStr(dr["Active"]);
                            temp.DateCreated = Tools.Tools.IifDT(dr["DateCreated"]);
                            //temp.DateUpdated = Tools.Tools.IifDate(dr["DateUpdated"]);
                            temp.WorksiteCode = Tools.Tools.IifStr(dr["Worksitedesc"]);
                            lst = temp;
                        }
                    }
                }
            }
        }
        catch (Exception ex)
        {
            lst.Username = "Error in retrieving record";
        }
        return lst;
    }
    protected void btnBack_Click(object sender, EventArgs e)
    {
        SessionManager.PageIndex = this.hfKeyId.Value;
        SessionManager.PageIndex = this.hfPageIndex.Value;
        Response.Redirect("~/DisplayRecord.aspx");
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

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

About the Author

Al Moje
Software Developer (Senior) ***
Philippines Philippines
MCTS - Microsoft Certified Technology Specialist.
An Accountant.
Had been developed Payroll Accounting System Application
Live in: Quezon City, Metro Manila Philippines
Could reached at email address: ag_mojedo@live.com

| Advertise | Privacy | Mobile
Web04 | 2.8.140721.1 | Last Updated 15 Oct 2011
Article Copyright 2011 by Al Moje
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid