Click here to Skip to main content
15,886,110 members
Articles / Web Development / ASP.NET

Bind Image from Database to DataGrid (web Application)

Rate me:
Please Sign up or sign in to vote.
3.27/5 (11 votes)
29 Apr 2007CPOL3 min read 83.1K   1.5K   23  
Handles uploading /downloading images into/from database to DataGrid
<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs" Inherits="_Default" %>

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

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    <title>Upload Download Image Web Application</title>
</head>
<body>
    <form id="form1" runat="server">
     <center>
    <h2> Upload Download Image Web Application </h2>
        <div>
       
          <h4> Upload Image </h4>
         <asp:Label ID="lblMessage" ForeColor="red" Font-Bold ="true"  runat="server" ></asp:Label>
          <br />
          <asp:FileUpload ID="imgUpload" runat="server" />
          <asp:LinkButton ID="lbtnUpload" Text ="Attach" runat ="server" ></asp:LinkButton>
          <br />
          <asp:Label ID="lblAttachedFile" runat="server" ></asp:Label>
           <br />
          <asp:Button ID="btnInsert" Text="Save" runat="server" ></asp:Button>
          <asp:Button ID="btnView" Text="View" runat="server" ></asp:Button>
          <br />
          <hr /> 
           <h4> Download Image </h4>
            <asp:DataGrid ID="dgBindImage" runat="server" AutoGenerateColumns="false" >
                <Columns>
                    <asp:TemplateColumn HeaderText="Images">
                        <ItemTemplate >
                            <asp:Label ID="lblCode"  Text='<%# Server.HtmlEncode(DataBinder.Eval(Container, "DataItem.imgID").ToString())%>' runat="server" />
                            <img id="imgPic" width="120" height="100" runat="server" />
                        </ItemTemplate>
                    </asp:TemplateColumn>
                </Columns>
            </asp:DataGrid>
        </div>
        </center>
    </form>
</body>
</html>

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)


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions