PC Review


Reply
Thread Tools Rate Thread

Displaying Images dynamically in GridView

 
 
King Coffee
Guest
Posts: n/a
 
      18th Nov 2009
Hi,

The following is the code snippet I'm trying to develop. The select method
GetPics returns a collection (filtered by Request["AptID"]) of image
filenames from a DB. The primary field returned by GetPics is "PicID". I
want the GridView to display the images per rowset filename DB field.

<asp:GridView ID="GridView1" Runat="server" DataSourceID="ObjectDataSource1"
DataKeyNames="PicID" onrowdatabound="GridView1_RowDataBound" >
<Columns>
<asp:templatefield HeaderText="Photo">
<itemtemplate>
<asp:Image ID="Image1" runat="server" />
</itemtemplate>
</asp:templatefield>
</Columns>
</asp:GridView>

<asp:ObjectDataSource ID="ObjectDataSource1"
TypeName=".Pics"
DataObjectTypeName="Pics"
SelectMethod="GetPics"
Runat="server" >
<SelectParameters>
<asp:QueryStringParameter QueryStringField="AptID" Type="Int32"
Name="AptId" />
</SelectParameters>
</asp:ObjectDataSource>
_________________________________________________________________________
protected void GridView1_RowDataBound(object sender,
GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = e.Row.FindControl("Image1") as Image;

img.ImageUrl = "~/Gallery/4/Thumbs/" + ???;
}
}

Thanks,
King


 
Reply With Quote
 
 
 
 
Miro
Guest
Posts: n/a
 
      18th Nov 2009
custom bind the image with a function...

take a look at this example:

http://www.pluralsight.com/community.../16/17507.aspx

here is an example I am using with an image control
Take a look at the databinding for the "ImageUrl" and the function inbehind
in the vb code.
In my datatable, i store just the jpg filename "ImageName".

<dxe:ASPxImage ID="aspximageDesignImage" runat="server" Height="150px"
Width="125px" AlternateText='<%#
Eval("ImageName") %>'
ImageUrl='<%#
ImagePathUrl(DataBinder.Eval(Container.DataItem, "ImageName")) %>'
ToolTip='<%# Eval("ItemDescription") %>'>
</dxe:ASPxImage>


Function ImagePathUrl(ByVal ImageName As String)
DesignBibImageLocation = "ProductImages/" & ImageName.Trim
Return DesignBibImageLocation
End Function

Hope this helps.

Miro

"King Coffee" <(E-Mail Removed)> wrote in message
news:F8394307-E8F5-4E36-83B4-(E-Mail Removed)...
> Hi,
>
> The following is the code snippet I'm trying to develop. The select method
> GetPics returns a collection (filtered by Request["AptID"]) of image
> filenames from a DB. The primary field returned by GetPics is "PicID". I
> want the GridView to display the images per rowset filename DB field.
>
> <asp:GridView ID="GridView1" Runat="server"
> DataSourceID="ObjectDataSource1"
> DataKeyNames="PicID" onrowdatabound="GridView1_RowDataBound" >
> <Columns>
> <asp:templatefield HeaderText="Photo">
> <itemtemplate>
> <asp:Image ID="Image1" runat="server" />
> </itemtemplate>
> </asp:templatefield>
> </Columns>
> </asp:GridView>
>
> <asp:ObjectDataSource ID="ObjectDataSource1"
> TypeName=".Pics"
> DataObjectTypeName="Pics"
> SelectMethod="GetPics"
> Runat="server" >
> <SelectParameters>
> <asp:QueryStringParameter QueryStringField="AptID" Type="Int32"
> Name="AptId" />
> </SelectParameters>
> </asp:ObjectDataSource>
> _________________________________________________________________________
> protected void GridView1_RowDataBound(object sender,
> GridViewRowEventArgs e)
> {
> if (e.Row.RowType == DataControlRowType.DataRow)
> {
> Image img = e.Row.FindControl("Image1") as Image;
>
> img.ImageUrl = "~/Gallery/4/Thumbs/" + ???;
> }
> }
>
> Thanks,
> King
>
>


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Dynamically getting images from Database and displaying on ASP.Netpage asharda@woh.rr.com Microsoft VB .NET 5 30th Jul 2008 01:27 PM
Dynamically displaying images in a gridview gnewsgroup@gmail.com Microsoft ASP .NET 11 6th Sep 2007 09:23 PM
Displaying images in gridview? =?Utf-8?B?Vk1J?= Microsoft C# .NET 1 24th Sep 2006 04:49 AM
Block images security feature / Images not displaying correctly =?Utf-8?B?cnN6ZWJyYXM=?= Microsoft Outlook Discussion 2 12th Jul 2006 10:04 PM
Need help displaying images dynamically in a table =?Utf-8?B?dHBlcnJp?= Microsoft ASP .NET 2 27th Jun 2005 01:50 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:26 AM.