Solved

display image from sql server in asp.net gridview

Posted on 2013-01-29
3
815 Views
Last Modified: 2013-01-30
I need to display rows from a table of images in Sql Server in a gridview.  The data is of type image, loaded as byte arrays.  I'm confused by the several methods in the literature: with or without handler, as a field or control, whatever.  Here's some of my [not working] code.  The other fields display just fine.
<asp:GridView ID="EditImagesGV" runat="server" AllowPaging="True" DataKeyNames="ImageId"
        AutoGenerateColumns="False" DataSourceID="EditImagesLDS">
        <Columns>
            <asp:TemplateField HeaderText="Choose action" ShowHeader="true">
               <ItemTemplate>
                <asp:Button ID="btnEditImagesGV" runat="server" CausesValidation="False" 
                        CommandName="Edit" Text="Edit">
                    </asp:Button> &nbsp;
                    <asp:Button ID="btnDeleteGVRecord" runat="server" CausesValidation="False" 
                        OnClientClick="return confirm('Are you sure you want to delete this record?')"
                        CommandName="Delete" Text="Delete" >
                    </asp:Button>
                </ItemTemplate>
                <EditItemTemplate>
                    <asp:Button ID="Button1" runat="server" CausesValidation="false" 
                        CommandName="Update" Text="Update">
                    </asp:Button> &nbsp;
                    <asp:Button ID="btnCancel" runat="server" CausesValidation="False" 
                        CommandName="Cancel" Text="Cancel">
                    </asp:Button>
                </EditItemTemplate>
            </asp:TemplateField>
            <asp:BoundField DataField="ImageId" HeaderText="ImageId" ReadOnly="True" SortExpression="ImageId" />
            <asp:Boundfield DataField="imageDisplayOrder" HeaderText="DisplayOrder" sortExpression="DisplayOrder" visible="true" />
            <asp:BoundField DataField="imageTitle" HeaderText="Title" Visible=true />
            <asp:BoundField DataField="imageDescription" HeaderText="Description" Visible=true />
            <asp:BoundField DataField="equipmentId" HeaderText="equipmentId" 
                ReadOnly="True" Visible="False" />
            <asp:BoundField DataField="imageFileName" HeaderText="FileName" 
                ReadOnly="True" SortExpression="imageFileName" />
            <asp:TemplateField HeaderText="Image">
            <ItemTemplate>
                <asp:Image ID="Image1" runat="server" width=150px CSSclass = "ImageZoom"
                    ImageURL=<%# eval("imageContent") %>  />
            </ItemTemplate>
        </asp:TemplateField>
        </Columns>
    </asp:GridView>
    <asp:LinqDataSource ID="EditImagesLDS" runat="server" enableUpdate=true EnableInsert=true EnableDelete=true
        ContextTypeName="lucidequipmentDataContext" EntityTypeName="" 
        OrderBy="imageDisplayOrder" 
        where= "equipmentID==@equipmentMasterID"
        TableName="equipmentImages">
        <UpdateParameters>
            <asp:Parameter name="imageTitle" type= "string" />
            <asp:Parameter Name="imageDescription" Type="String" />
            <asp:Parameter Name="imageDisplayOrder" Type=Int32 />
        </UpdateParameters>
    </asp:LinqDataSource>

Open in new window


in the code behind I've got

 Protected Sub EditImagesLDS_Selecting(sender As Object, e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles EditImagesLDS.Selecting
        Dim keyId As Integer = Session("keyId")
        e.WhereParameters("equipmentMasterID") = keyId
    End Sub

Open in new window


An equipmentMaster table supplies an ID which is used to pull the images from the equipmentImages table associated with that ID.

I need some direction
0
Comment
Question by:Mark Klein
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 10

Expert Comment

by:deviprasadg
ID: 38833894
0
 
LVL 10

Accepted Solution

by:
Monica P earned 500 total points
ID: 38834409
0
 

Author Closing Comment

by:Mark Klein
ID: 38835657
both suggestions probably will work, but the second was easier for me.  I built a similar handler. thanks for the help
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Upgrading to SQL Server 2015 Express 2 34
Convert VBA UDF to SQl SERVER UDF 4 50
Linked Server - SP with Param to VIew 7 22
Need SSIS project 2 28
Introduction In my previous article (http://www.experts-exchange.com/Microsoft/Development/MS-SQL-Server/SSIS/A_9150-Loading-XML-Using-SSIS.html) I showed you how the XML Source component can be used to load XML files into a SQL Server database, us…
Slowly Changing Dimension Transformation component in data task flow is very useful for us to manage and control how data changes in SSIS.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.

733 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question