Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / ASP.NET / General / March 2008

Tip: Looking for answers? Try searching our database.

Adding path info to an GridView asp:Image bound column

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
musosdev - 25 Mar 2008 17:38 GMT
Hi

I need to add the path to my images directory to the DataUrlField of a bound
ImageField in a GridView, but I can't work out how to do this.

Is there a a Path property I'm missing? Or can I append to each column as it
is inserted (by over-riding some sort of Populate method)?

Thanks,

Dan
Masudur - 25 Mar 2008 20:25 GMT
> Hi
>
[quoted text clipped - 7 lines]
>
> Dan

Hi,

Take a look at this article...

http://msdn2.microsoft.com/en-us/library/aa479350.aspx

do check out how ResolveUrl method is used.

Thanks
Masudur
Steven Cheng - 26 Mar 2008 02:39 GMT
Hi Dan,

Your question here is to how to add some custom path into the GridView
imagefield. Generally, you can use the "DataImageUrlField" and
"DataImageUrlFormatString" property to provide basic url and formatting
info. For example:

<asp:ImageField DataImageUrlField="title"
DataImageUrlFormatString="query.aspx?title={0}" ></asp:ImageField>

this can help you generate composite url path from the databound field
value. However, if you want further customization, I think you may consider
either of the following means:

1. You can use TemplateField and manuallyl put <asp:Image > control in it.
Thus, you can use inline databinding expression and  inject the Image path
generation code logic into the databinding expression(you can define a
custom function in codebehind and call it).

=================
...............
   <ItemTemplate>
                   <asp:Label ID="Label1" runat="server" Text='<%#
Bind("name") %>'></asp:Label>
                   
                    <asp:Image ID="img" runat="server" ImageUrl='<%#  
Your binding function or code logic here%>' />
              </ItemTemplate>
           </asp:TemplateField>
=========================

2. You can also use the RowDataBound event of Gridview. There, you can
access the databound fields and customize existing controls in the GridView
cell. e.g.

============
 protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs
e)
   {
       Trace.Write("GridView1_RowDataBound");
       if (e.Row.RowType == DataControlRowType.DataRow)
       {

           DataRowView drv = (DataRowView)e.Row.DataItem;

           long id = (long)drv[0];

           Image img = e.Row.FindControl("img") as Image;
           img.ImageUrl = ......;

       }
   }

============

Hope this helps.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
msdnmg@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: =?Utf-8?B?bXVzb3NkZXY=?= <musoswire@community.nospam>
>Subject: Adding path info to an GridView asp:Image bound column
>Date: Tue, 25 Mar 2008 09:38:06 -0700

>Hi
>
[quoted text clipped - 7 lines]
>
>Dan
musosdev - 27 Mar 2008 12:03 GMT
Thanks to both of you. I've sorted the problem with a TemplateField.

Cheers, Dan.

> Hi Dan,
>
[quoted text clipped - 102 lines]
> >
> >Dan

Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.