Andy_Solo
BANNED | Редактировать | Профиль | Сообщение | Цитировать | Сообщить модератору Andy_Solo Цитата: А как в DetailsView отобразить графическое поле из базы данных? | Заработало! В DetailsView создал поле: <asp:ImageField HeaderText="Визуальный контакт" DataImageUrlField="ID" DataImageUrlFormatString="Photo.ashx?ID={0}" AlternateText="Фотография"> </asp:ImageField> Создал Photo.ashx: <%@ WebHandler Language="C#" Class="Photo" %> using System; using System.Web; using System.IO; using System.Data.SqlClient; using System.Data; using System.Configuration; public class Photo : IHttpHandler { public bool IsReusable { get { return true; } } public void ProcessRequest (HttpContext context) { HttpResponse response = context.Response; HttpRequest request = context.Request; response.ContentType = "image/jpeg"; response.Cache.SetCacheability(HttpCacheability.Public); response.BufferOutput = false; writeSingleImage(Convert.ToInt32(request.QueryString["ID"]), response.OutputStream); response.End(); } public void writeSingleImage(int ID, Stream output) { SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["InfoPagesDB"].ConnectionString); string query = "select Photo from Worker where (Id = @id) and (Photo is not null)"; SqlCommand command = new SqlCommand(query, connection); SqlParameter param0 = new SqlParameter("@id", SqlDbType.Int, 4); param0.Value = ID; command.Parameters.Add(param0); connection.Open(); byte[] d = ((byte[])(command.ExecuteScalar())); output.Write(d, 0, d.Length); connection.Close(); } } |