RE: Adding path info to an GridView asp:Image bound column



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@xxxxxxxxxxxxxx

==================================================
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@xxxxxxxxxxxxxxxx>
Subject: Adding path info to an GridView asp:Image bound column
Date: Tue, 25 Mar 2008 09:38:06 -0700


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


.



Relevant Pages

  • RE: Adding path info to an GridView asp:Image bound column
    ... Your question here is to how to add some custom path into the GridView ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • RE: Membership Provider Woes
    ... perform forms authentication in your ASP.NET web application. ... you also want to add additional custom datainto the ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: gridview not exporting to excel
    ... I suggest you try saving the exported file as xls or ... server-side gridview databinding and the code logic of flushing the data to ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: Restrict size of Custom Task Pane
    ... restrict the size of a custom task pane when users stretch it. ... Microsoft Online Community Support ... For MSDN subscribers whose posts are left unanswered, ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.office.developer.com.add_ins)
  • RE: GridView with Password Field
    ... for Gridview editing, I think you can convert the certain column(in ... Microsoft MSDN Online Support Lead ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.webcontrols)