Images on server.

R

rcoco

ImageUrl='<%# "/Images/" +DataBinder.Eval(Container.DataItem,
"MoodToday") + "../Images/sad.gif"%>'

Using the code above, what URL are you expecting to get in the output?- Hide quoted text -

- Show quoted text -

I want to get Sad.gif when its Bad mood that was selected.
thanks
 
G

Guest

I want to get Sad.gif when its Bad mood that was selected.
thanks- Hide quoted text -

I will rephrase the question:

"/Images/" + {something} + "../Images/sad.gif" = ?
 
R

rcoco

that's for getting the ImageUrl .

Alexey,
You gave this example and I've just nrealised that actually I did not
understand it:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
DataBinder.Eval(Container.DataItem, "Mood") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
Could you try to explain to me please?
 
G

Guest

Alexey,
You gave this example and I've just nrealised that actually I did not
understand it:
<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
DataBinder.Eval(Container.DataItem, "Mood") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>
Could you try to explain to me please?- Hide quoted text -

- Show quoted text -

I understand that you don't understand. But you have to understand
that "A"+"B" = "AB".

The goal is to show an image, which is located somewhere on a server.
I don't know exactly what url does your image, but I suppose it is
something like this

/Images/laughing.gif
/Images/sad.gif

To check if I'm right (and the url is right) type that url in the
address bar of your browser.

For example:

http://servername/Images/laughing.gif
http://localhost/Images/laughing.gif (if you do it locally)

You should see an image.

If you don't see it - the url is wrong, and you have to find the right
url.

A: What is the right url?

Now, when we know an url, we come to another question: what value do
you have in the database.

MoodToday is.... a number, a string.... ? what?

Assuming it is a string.
Assuming it is either "sad", or "laughing".

B: What is the value of MoodToday?

Please answer these 2 questions for me and we could finally check if
"A"+"B" = "AB"
 
R

rcoco

I understand that you don't understand. But you have to understand
that "A"+"B" = "AB".

The goal is to show an image, which is located somewhere on a server.
I don't know exactly what url does your image, but I suppose it is
something like this

/Images/laughing.gif
/Images/sad.gif

To check if I'm right (and the url is right) type that url in the
address bar of your browser.

For example:

http://servername/Images/laughing.gifhttp://localhost/Images/laughing.gif(if you do it locally)

You should see an image.

If you don't see it - the url is wrong, and you have to find the right
url.

A: What is the right url?

Now, when we know an url, we come to another question: what value do
you have in the database.

MoodToday is.... a number, a string.... ? what?

Assuming it is a string.
Assuming it is either "sad", or "laughing".

B: What is the value of MoodToday?

Please answer these 2 questions for me and we could finally check if
"A"+"B" = "AB"- Hide quoted text -

- Show quoted text -

The right URL is http://localhost/Images/laughing.gif,
Mood today is a string, the value of Mood Today is text 16
Thanks
 
R

rcoco

The right URL ishttp://localhost/Images/laughing.gif,
Mood today is a string, the value of Mood Today is text 16
Thanks- Hide quoted text -

- Show quoted text -

I forgot the value that are in MoodToday are Good Mood & Bad Mood.
Thanks
 
L

Larry Bud

Thanks Ray,
When I did this:ImageUrl="../Images/logo.JPG", Even on serverside
cannot see the image.
Thanks.

No offense, but how in the world are you a .NET developer yet don't
understand such a simple concept as relative address of an HTML image?
 
M

Mark Rae

No offense, but how in the world are you a .NET developer yet don't
understand such a simple concept as relative address of an HTML image?

:)

I am staggered at Alexey's patience with this guy - I gave up days ago...

I'd hate to be his boss!
 
G

Guest

I forgot the value that are in MoodToday are Good Mood & Bad Mood.
Thanks- Hide quoted text -

- Show quoted text -

Okay, going back to the code I sent you some time ago:

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" :
"laughing") + ".gif" %>'/>
</ItemTemplate>
</asp:TemplateColumn>

The code above would show one of two images:

MoodToday = "Bad Mood" ---> /images/sad.gif
otherwise ---> /images/laughing.gif

If you will have any problem with that Image Control you should debug
your code.

It could be done, e.g. like the following example:

<asp:TemplateColumn>
<ItemTemplate>
<asp:Image Runat="server" ID="Image1" ImageUrl='<%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" :
"laughing") + ".gif" %>'/>

Current Mood in the database is: <%#
DataBinder.Eval(Container.DataItem, "MoodToday") %>

Image URL is: <%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" :
"laughing") + ".gif" %>

</ItemTemplate>
</asp:TemplateColumn>

I hope I didn't make any mistake and my code will work for you and we
finally close the issue with images :)
 
G

Guest

:)

I am staggered at Alexey's patience with this guy - I gave up days ago...

I'd hate to be his boss!

The author deserve admiration for his persistence and stubbornness :)
 
R

rcoco

Thanks Alexey for the help and for the patience.
The code
Image URL is: <%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" : "laughing") + ".gif" %>

I get the error Specified cast is not valid at run time.

And when I changed the code to
<asp:Image id=Image1 runat="server" ImageUrl='<
%#DataBinder.Eval(Container.DataItem,"MoodToday")=="Bad
Mood"?"sad":"laughing" )+".gif"%>' Visible="True">
</asp:Image>

Only the Image laughing .gif appears whether Good Mood or Bad Mood is
selected.
Why is it so?
 
G

Guest

Thanks Alexey for the help and for the patience.
The code
Image URL is: <%# "/Images/" +
((string)DataBinder.Eval(Container.DataItem, "MoodToday") == "Bad
Mood" ? "sad" : "laughing") + ".gif" %>

I get the error Specified cast is not valid at run time.

And when I changed the code to
<asp:Image id=Image1 runat="server" ImageUrl='<
%#DataBinder.Eval(Container.DataItem,"MoodToday")=="Bad
Mood"?"sad":"laughing" )+".gif"%>' Visible="True">
</asp:Image>

Only the Image laughing .gif appears whether Good Mood or Bad Mood is
selected.
Why is it so?

Have you tried to debug it?

Put this line as I already told you

Current Mood in the database is: ***<%#
DataBinder.Eval(Container.DataItem, "MoodToday") %>***

If you believe that a "Bad Mood" is selected (it has to be saved(!))
then you will see

***Bad Mood***

Otherwise you will see

***Good Mood***
***abracadabra***
******
and so on
 
R

rcoco

Have you tried to debug it?

Put this line as I already told you

Current Mood in the database is: ***<%#
DataBinder.Eval(Container.DataItem, "MoodToday") %>***

If you believe that a "Bad Mood" is selected (it has to be saved(!))
then you will see

***Bad Mood***

Otherwise you will see

***Good Mood***
***abracadabra***
******
and so on- Hide quoted text -

- Show quoted text -
Thanks Alexey,
It has worked properly. I had to select Bad Mood By default like you
had advised me.
I Really Want to thank you so so much it has worked so well. Thank you
especially for yo patience it's unusial.
Thanks again and to the rest who helped me in giving me a clou.
 
R

rcoco

Thanks Alexey,
It has worked properly. I had to select Bad Mood By default like you
had advised me.
I Really Want to thank you so so much it has worked so well. Thank you
especially for yo patience it's unusial.
Thanks again and to the rest who helped me in giving me a clou.- Hide quoted text -

- Show quoted text -

Sorry again Every thing was going on well but all of a sudden I got a
wired reaction:
Why is it that when I insert data I fast get an error :
Specified cast is not valid.
But When I run the site for the second time I find the data was saved
the right image was selected! Actually I can say every thing works
well apart that when ever I attempt to insert data this error appears:
Specified cast is not valid. on line:
<asp:Image id=Image1 runat="server" ImageUrl='<%#"/Images/"+
((string)DataBinder.Eval(Container.DataItem,"MoodToday")=="Bad
Mood"?"sad":"laughing") +".gif"%>' ImageAlign="Middle">.
Thanks
 
R

rcoco

Sorry again Every thing was going on well but all of a sudden I got a
wired reaction:
Why is it that when I insert data I fast get an error :
Specified cast is not valid.
But When I run the site for the second time I find the data was saved
the right image was selected! Actually I can say every thing works
well apart that when ever I attempt to insert data this error appears:
Specified cast is not valid. on line:
<asp:Image id=Image1 runat="server" ImageUrl='<%#"/Images/"+
((string)DataBinder.Eval(Container.DataItem,"MoodToday")=="Bad
Mood"?"sad":"laughing") +".gif"%>' ImageAlign="Middle">.
Thanks- Hide quoted text -

- Show quoted text -

Actually the error reads: System.InvalidCastException: Specified cast
is not valid.

and the stack Trace

[InvalidCastException: Specified cast is not valid.]
ASP.DashBoard_aspx.__DataBind__control16(Object sender, EventArgs
e) in c:\inetpub\wwwroot\Dash_Board\DashBoard.aspx:46
System.Web.UI.Control.OnDataBinding(EventArgs e)
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.Control.DataBind()
System.Web.UI.WebControls.DataGrid.CreateItem(Int32 itemIndex,
Int32 dataSourceIndex, ListItemType itemType, Boolean dataBind, Object
dataItem, DataGridColumn[] columns, TableRowCollection rows,
PagedDataSource pagedDataSource)
System.Web.UI.WebControls.DataGrid.CreateControlHierarchy(Boolean
useDataSource)
System.Web.UI.WebControls.BaseDataList.OnDataBinding(EventArgs e)
System.Web.UI.WebControls.BaseDataList.DataBind()
Dash_Board.DashBoard.Bind() in c:\inetpub\wwwroot\dash_board
\dashboard.aspx.cs:109
Dash_Board.DashBoard.dgis_ItemCommand(Object source,
DataGridCommandEventArgs e) in c:\inetpub\wwwroot\dash_board
\dashboard.aspx.cs:176

System.Web.UI.WebControls.DataGrid.OnUpdateCommand(DataGridCommandEventArgs
e)
System.Web.UI.WebControls.DataGrid.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args)
System.Web.UI.WebControls.DataGridItem.OnBubbleEvent(Object source,
EventArgs e)
System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs
args)
System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e)

System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String
eventArgument)
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler
sourceControl, String eventArgument)
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
System.Web.UI.Page.ProcessRequestMain()

Help me please.
Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top