473,405 Members | 2,210 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

I need to change a GridView image file path programmatically...

I have this in my aspx file (using c#):
<asp:ImageButton ID="Imagebutton1" runat="server" alt='<%# Eval
( "name" ) %>' CommandName="select"
ImageUrl='<%#
Eval ( "image_file_name", "~/images/categories/{0}" ) %>' Width="50%" /
>
Sometimes the folder of the default image will be in /images/products
and not in /images/categories.
Is there a way to change this in my c# file under certain conditions?
Thanks,
Trint

Apr 18 '07 #1
4 5302
ImageUrl='<%# DetectImagePath(Eval("image_file_name")) %>'

(I don't use eval, not sure if that's correct syntax)

then in code behind:

protected string DetectImagePath(object filename)
{
string sFileName = (string) filename;

if(File.Exists(String.Format("~/images/categories/{0}", sFileName))
return String.Format("~/images/categories/{0}", sFileName);
else if(File.Exists(String.Format("~/images/products/{0}", sFileName))
return String.Format("~/images/products/{0}", sFileName);
else
return "";
}


"trint" <tr***********@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
>I have this in my aspx file (using c#):
<asp:ImageButton ID="Imagebutton1" runat="server" alt='<%# Eval
( "name" ) %>' CommandName="select"
ImageUrl='<%#
Eval ( "image_file_name", "~/images/categories/{0}" ) %>' Width="50%" /
>>

Sometimes the folder of the default image will be in /images/products
and not in /images/categories.
Is there a way to change this in my c# file under certain conditions?
Thanks,
Trint

Apr 18 '07 #2
ImageUrl='<%# DetectImagePath(Eval("image_file_name")) %>'

(I don't use eval, not sure if that's correct syntax)

then in code behind:

protected string DetectImagePath(object filename)
{
string sFileName = (string) filename;

if(File.Exists(String.Format("~/images/categories/{0}", sFileName))
return String.Format("~/images/categories/{0}", sFileName);
else if(File.Exists(String.Format("~/images/products/{0}", sFileName))
return String.Format("~/images/products/{0}", sFileName);
else
return "";
}
"trint" <tr***********@gmail.comwrote in message
news:11**********************@q75g2000hsh.googlegr oups.com...
>I have this in my aspx file (using c#):
<asp:ImageButton ID="Imagebutton1" runat="server" alt='<%# Eval
( "name" ) %>' CommandName="select"
ImageUrl='<%#
Eval ( "image_file_name", "~/images/categories/{0}" ) %>' Width="50%" /
>>

Sometimes the folder of the default image will be in /images/products
and not in /images/categories.
Is there a way to change this in my c# file under certain conditions?
Thanks,
Trint

Apr 18 '07 #3
On Apr 18, 4:39 pm, trint <trinity.sm...@gmail.comwrote:
Normally when dealing with Dynamica Images, either reading them from
database or something else you'd like to have a Dynamic Image control.
We have one in our Ajax library, you can see it at;
http://ajaxwidgets.com/AllControlsSa...goCreator.aspx

..t

Apr 18 '07 #4
On Apr 18, 1:22 pm, "djmc" <allnightco...@gmail.comwrote:
ImageUrl='<%# DetectImagePath(Eval("image_file_name")) %>'

(I don't use eval, not sure if that's correct syntax)

then in code behind:

protected string DetectImagePath(object filename)
{
string sFileName = (string) filename;

if(File.Exists(String.Format("~/images/categories/{0}", sFileName))
return String.Format("~/images/categories/{0}", sFileName);
else if(File.Exists(String.Format("~/images/products/{0}", sFileName))
return String.Format("~/images/products/{0}", sFileName);
else
return "";

}
"trint" <trinity.sm...@gmail.comwrote in message

news:11**********************@q75g2000hsh.googlegr oups.com...
I have this in my aspx file (using c#):
<asp:ImageButton ID="Imagebutton1" runat="server" alt='<%# Eval
( "name" ) %>' CommandName="select"
ImageUrl='<%#
Eval ( "image_file_name", "~/images/categories/{0}" ) %>' Width="50%" /
Sometimes the folder of the default image will be in /images/products
and not in /images/categories.
Is there a way to change this in my c# file under certain conditions?
Thanks,
Trint- Hide quoted text -

- Show quoted text -
this works.
Thanks,
Trint

Apr 19 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: theKirk | last post by:
using Visual Studio 2005 C# ASP.NET I know there has to be a simple way to do this....I want to use C# in a code behind for aspx. Populate a GridView from an xml file Add Fields to the...
1
by: | last post by:
I'm wondering if it's possible, outside of the declaration of an ASP.NET 2.0 GridView, to programmatically style individual columns. For example, I might want to make the text in a particular...
3
by: Larry | last post by:
I've set up a list of image filesnames in a listview control(lvSrcFileList), I'm using the selectedIndexChange event to select which file is being displayed in a picturebox control(pbImagePreview)....
7
by: | last post by:
Hello, Does anyone have an idea on how I can filter the data in the gridview control that was returned by an sql query? I have a gridview that works fine when I populate it with data. Now I...
5
by: Brian McClellan | last post by:
Just wondering if anyone has a simple example of creating a gridview completely programmatically, i'm not doing anything terribly sophisticated. When creating the gridview declaratively evertying...
3
by: Mirek Endys | last post by:
Hello all, I have this problem. I have a windows service and I would like to put there Settings for starting this service. Because of this service is running under NETWORK_SERVICE account, what...
4
by: John Smith | last post by:
Hello, I'm not sure if these are the appropriate forums for my question since it is closer to about Visual Studio 2005 than it is about .NET framework. So please pardon me and direct me to a...
2
by: michel | last post by:
Hi, there is a gridview with a Commandfield. I would like to set the 'ShowEditButton' on 'true' programmatically. I tried two ways without succes: with "'Dim cf As CommandField with "'Dim cf...
1
by: edwinparker | last post by:
Hi, I'm trying to convert a gridview to an excel report and have one small hang up. So far I've been able to create my gridview and export it to excel ok, but in my gridview I have an image. The...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.