title: Asp.net c# displaying multiple images from single database record
body: <p>Building my first .net application, so please be patient of my novice level.</p>
  
  <p>I am collecting data from users and storing into SQL. Each record has several data fields and up to four images (yes causes very large records, but volume is small).</p>
  
  <p>Now I need to be able to display those images back to a user. I want to do this using a page layout similar to below, but don't know how to implement a handler that can deal with this. The record the page displays is coming from a query string, with the only value being the questionID.</p>
  
  <pre><code>&lt;%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="Submit_Detail.aspx.cs" Inherits="cs1.Submit.Submit_Detail" %&gt;
  &lt;asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server"&gt;
  &lt;asp:FormView ID="Submit_tDetail" runat="server" ItemType="cs1.Models.Questions" SelectMethod ="GetQuestion" RenderOuterTable="false"&gt;
      &lt;ItemTemplate&gt;
          &lt;div&gt;
              &lt;h1&gt;&lt;%#:Item.KeyObjective %&gt;&lt;/h1&gt;
          &lt;/div&gt;
          &lt;br /&gt;
          &lt;table&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;img src="&lt;%#:Item.ImageFile %&gt;" style="border:solid; height:300px" alt="No Image"/&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;img src="&lt;%#:Item.ImageFile2 %&gt;" style="border:solid; height:300px" alt="No Image" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td&gt;
                      &lt;img src="&lt;%#:Item.ImageFile3 %&gt;" style="border:solid; height:300px" alt="No Image"/&gt;
                  &lt;/td&gt;
                  &lt;td&gt;
                      &lt;img src="&lt;%#:Item.ImageFile4 %&gt;" style="border:solid; height:300px" alt="No Image" /&gt;
                  &lt;/td&gt;
              &lt;/tr&gt;
              &lt;tr&gt;
                  &lt;td style="vertical-align: top; text-align:left;"&gt;
                      &lt;b&gt;Author:&lt;/b&gt;&lt;br /&gt;&lt;%#:Item.Author %&gt;
                      &lt;br /&gt;
                      &lt;span&gt;&lt;b&gt;Submit Date:&lt;/b&gt;&amp;nbsp;&lt;%#: Item.SubmitDate %&gt;&lt;/span&gt;
                      &lt;br /&gt;
                      &lt;span&gt;&lt;b&gt;Stem:&lt;/b&gt;&amp;nbsp;&lt;%#:Item.Stem %&gt;&lt;/span&gt;
                      &lt;br /&gt;
                      &lt;/td&gt;
                  &lt;/tr&gt;
              &lt;/table&gt;
          &lt;/ItemTemplate&gt;
      &lt;/asp:FormView&gt;
  &lt;/asp:Content&gt;
  </code></pre>
  
  <p>Current code behind for the page:</p>
  
  <pre><code>namespace cs1.Submit
      {
      public partial class Submit_Detail : System.Web.UI.Page
      {
          protected void Page_Load(object sender, EventArgs e)
          {
  
          }
      public IQueryable&lt;Questions&gt; GetQuestion([QueryString("QuestionID")] int? QuestionId)
      {
          var _db = new cs1.Models.ProductContext();
          IQueryable&lt;Questions&gt; query = _db.Questions;
          if (QuestionId.HasValue &amp;&amp; QuestionId &gt; 0)
          {
              query = query.Where(p =&gt; p.QuestionID == QuestionId);
          }
          else
          {
              query = null;
          }
          return query;
      }
  }
  }
  </code></pre>
  
  <p>Each image in SQL server has three columns for binaryData, ContentType, and ImageName.</p>
  
  <p>ImageFile,
  Image1Content,
  Image1Name,
  Image2File,
  Image2Content,
  Image2Name,
  etc.</p>