使用DataGrid顯示來自於資料庫的圖象

來源:互聯網
上載者:User
前言
我們如何建立一個DataGrid列,顯示從資料庫中獲得的映像?
這是一個經常被問及的關於DataGrid控制項的問題,而且其他可以很容易地通過結合你已經知道的關於模板列的內容以及一點點關於HTTP處理控制代碼(HTTP Handler)的知識來回答。
下面使用NorthWind資料庫的Employees表來在一個DataGrid中顯示資料庫中的映像。
代碼
--- BindImg.aspx
<%@ Page language="c#" Codebehind="BindImg.aspx.cs" AutoEventWireup="false" Inherits="ShowImg.BindImg" %>
<HTML>
<HEAD>
<title>BindImg</title>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<FONT face="宋體">
<asp:DataGrid id="MyDataGrid" runat="server" AutoGenerateColumns="False" Width="632px">
<AlternatingItemStyle BackColor="Beige"></AlternatingItemStyle>
<HeaderStyle HorizontalAlign="Center"></HeaderStyle>
<Columns>
<asp:TemplateColumn HeaderText="Photo">
<ItemTemplate>
<img src='<%# "GetImg.ashx?ID="+DataBinder.Eval(Container.DataItem,"EmployeeID")%>'>
</ItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="LastName" HeaderText="Last Name"></asp:BoundColumn>
<asp:BoundColumn DataField="FirstName" HeaderText="First Name"></asp:BoundColumn>
<asp:BoundColumn DataField="title" HeaderText="Title"></asp:BoundColumn>
</Columns>
</asp:DataGrid></FONT>
</form>
</body>
</HTML>
--- BindImg.aspx.cs
using System;
using System.Data;
using System.Drawing;
using System.Web;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.