Mark Klein
asked on
display image from sql server in asp.net gridview
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.
in the code behind I've got
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
<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>
<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>
<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>
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
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
Please refer: http://aspsnippets.com/Articles/Display-images-from-SQL-Server-Database-in-ASP.Net-GridView-control.aspx
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
both suggestions probably will work, but the second was easier for me. I built a similar handler. thanks for the help