Manoj Maharana

Manoj Maharana

  • NA
  • 362
  • 128k

how to retrive binary data in mssql on listview eval

Sep 29 2016 6:29 AM
I want to bind a image (which is stored in binary format column name image(varbinary)) in list view in c#.. i am trying this two but not working..
 
<img src='<%# string.Format("data:image/gif;base64,{0}",Convert.ToBase64String((byte[])Eval("image")))%>'/>--%>                 <%--<asp:Image ID="Image10" runat="server" Height="100px" ImageUrl='<%# "ShowImage.ashx?id=" + Eval("image") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("image")) %>' />--%>
here is the code:
  1. <div>  
  2.         
  3.         <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:VeteransDirectoryConnectionString %>" SelectCommand=  
  4.         "SELECT [EventID], [OrganizationName], [Title], [DescriptionShort], [DescriptionLong], [Location], [EventDate], [URL], (CASE WHEN URL IS NULL OR URL = '' THEN CAST(0 AS bit) ELSE CAST(1 AS bit) END) AS URLLink, [FileName], (CASE WHEN FileName IS NULL OR FileName = '' THEN CAST(0 AS bit) ELSE CAST(1 AS bit) END) AS FileLink, [EventTime],image FROM [t_Event] WHERE ([EventID] = @EventID)">  
  5.   
  6.   
  7.              <SelectParameters>  
  8.                 <asp:QueryStringParameter Name="EventID" QueryStringField="eventid" Type="Int32" />  
  9.             </SelectParameters>  
  10.         </asp:SqlDataSource>  
  11.         <br />  
  12.         <div style="padding: 0px 10px 20px 10px;">  
  13.         <asp:ListView ID="ListView1" runat="server" DataKeyNames="EventID" DataSourceID="SqlDataSource1">  
  14.             <EmptyDataTemplate>  
  15.                 <span>No data for this event was found.</span>  
  16.             </EmptyDataTemplate>  
  17.             <ItemTemplate>  
  18.                 <span class="listCalLabel">Organization:</span>    
  19.                 <asp:Label ID="OrganizationNameLabel" runat="server" Text='<%# Eval("OrganizationName") %>' CssClass="listCalText" />  
  20.                 <br /><br />  
  21.                 <span class="listCalLabel">Event:</span>    
  22.                 <asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>' CssClass="listCalText" />  
  23.                 <br /><br />  
  24.                 <span class="listCalLabel">Short Description:</span>    
  25.                 <asp:Label ID="DescriptionShortLabel" runat="server" Text='<%# Eval("DescriptionShort") %>' CssClass="listCalText" />  
  26.                 <br /><br />  
  27.                 <span class="listCalLabel">Long Description:</span>    
  28.                 <asp:Label ID="DescriptionLongLabel" runat="server" Text='<%# Eval("DescriptionLong") %>' CssClass="listCalText" />  
  29.                 <br /><br />  
  30.                 <span class="listCalLabel">Location:</span>    
  31.                 <asp:Label ID="LocationLabel" runat="server" Text='<%# Eval("Location") %>' CssClass="listCalText" />  
  32.                 <br /><br />  
  33.                 <span class="listCalLabel">Event Date:</span>    
  34.                 <asp:Label ID="EventDateLabel" runat="server" Text='<%# Eval("EventDate", "{0:MM/dd/yyyy}") %>' CssClass="listCalText" />  
  35.                 <br /><br />  
  36.                 <span class="listCalLabel">Event Time:</span>    
  37.                 <asp:Label ID="EventTimeLabel" runat="server" Text='<%# Eval("EventTime") %>' CssClass="listCalText" />  
  38.                 <br /><br />  
  39.                 <span class="listCalLabel"><asp:Label ID="lblURL" runat="server" Visible='<%# Eval("URLLink") %>' Text="Additional Info (website):" ></asp:Label></span>  
  40.                 <br />  
  41.                 <asp:HyperLink ID="URLHyperLink" runat="server" Text='<%# Eval("URL") %>' NavigateUrl='<%# Eval("URL") %>' Visible='<%# Eval("URLLink") %>' Target="_blank" CssClass="listLink" />  
  42.                 <br /><br />  
  43.                 <span class="listCalLabel"><asp:Label ID="lblFile" runat="server" Visible='<%# Eval("FileLink") %>' Text="Additional Info (file):"></asp:Label></span>  
  44.                 <br />  
  45.                 <asp:HyperLink ID="URLFile" runat="server" Text='<%# Eval("FileName") %>' NavigateUrl='<%# "EventFiles/" + Eval("FileName") %>' Visible='<%# Eval("FileLink") %>' Target="_blank" CssClass="listLink" />  
  46.                 <br /><br />  
  47. <%--                <img src='<%# string.Format("data:image/gif;base64,{0}",Convert.ToBase64String((byte[])Eval("image")))%>'/>--%>  
  48.                 <%--<asp:Image ID="Image10" runat="server" Height="100px" ImageUrl='<%# "ShowImage.ashx?id=" + Eval("image") %>' GenerateEmptyAlternateText="True" Visible='<%# ShowImg(Eval("image")) %>' />--%>  
  49.                 <br /></span>  
  50.             </ItemTemplate>  
  51.             <LayoutTemplate>  
  52.                 <div id="itemPlaceholderContainer" runat="server" style="">  
  53.                     <span runat="server" id="itemPlaceholder" />  
  54.                 </div>  
  55.                 <div style="">  
  56.                 </div>  
  57.             </LayoutTemplate>  
  58.         </asp:ListView>  
  59.         <asp:Button ID="btnOK" runat="server" OnClientClick="window.close(); return false;" Text="Close Event Detail" CssClass="btn btn-default" />  
  60.         <br />  
  61.         <br />  
  62.   
  63.         </div>  
  64.     </div>  
 what should i do??? how to retrieve the image and show ina a webform ??

Answers (6)