473,320 Members | 1,823 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,320 software developers and data experts.

inline code in a server control

I have a datalist bound to a dataset.

In the Items template I have a Image which was supposed to changed depending
on a certain value retrieved from the dataset.

I have the ImageUrl attribute for the Image which I want to change

ImageUrl='...images\' <%# DataBinder.Eval(Container,
"DataItem.NeedForCover")%>'.BMP'> but it complains: the server tag is not
well formed. All I want to get from the dataset is the string.

How can I make it work ?

Also is there a way to put some kind of condition before an attribute like
we did with ASP f.e:

<%#if DataBinder.Eval(Container, "DataItem.NeedForCover")=True then %>
ImageUrl='...\images\HAPPY.BMP'>
<%# else %>
ImageUrl='...\images\SAD.BMP'>
<%# End if %>

Please help,

Thank everyone.

Feb 9 '06 #1
2 4604
One thing you can use is the ItemDataBound event, which is fired after each
event. Also, if you are simply going to append data from the datasource
(which is what it looks like you are doing for the ImageUrl attribute, try
this overload of the DataBinder.Eval method:

ImageUrl='<%#
DataBinder.Eval(Container,"DataItem.NeedForCover", "images/{0}.BMP") %>'

This code would return a string such as:

ImageUrl='images/yourimagename.BMP'

It basically replaces the {0} with the specified DataItem field.
If you have more complex strings you want to create, you can do that using
the ItemDataBound event. Here is an example of how to do the same thing
using this event:

Private Sub datMembers_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datMembers.ItemDataBound
CType(e.Item.FindControl("imgYourImageID"),
System.Web.UI.WebControls.Image).ImageUrl="images/" &
e.Item.DataItem("NeedForCover") & ".BMP"
End Sub

Obviously you can use any type of code you want in this event, including
conditional statements. This event is triggered after the individual Item
has been databound, so it can also be used to check what value was assigned
from the datasource (sometimes you want to check for a value of "" or maybe
replace "" with "&nbsp;" or a default value, or any number of other things
you may want to do). Hopefully you can solve your problems using these
techniques, if you need more help feel free to ask. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Gentian" <Ge*****@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I have a datalist bound to a dataset.

In the Items template I have a Image which was supposed to changed
depending
on a certain value retrieved from the dataset.

I have the ImageUrl attribute for the Image which I want to change

ImageUrl='...images\' <%# DataBinder.Eval(Container,
"DataItem.NeedForCover")%>'.BMP'> but it complains: the server tag is not
well formed. All I want to get from the dataset is the string.

How can I make it work ?

Also is there a way to put some kind of condition before an attribute like
we did with ASP f.e:

<%#if DataBinder.Eval(Container, "DataItem.NeedForCover")=True then %>
ImageUrl='...\images\HAPPY.BMP'>
<%# else %>
ImageUrl='...\images\SAD.BMP'>
<%# End if %>

Please help,

Thank everyone.

Feb 10 '06 #2
Thanks a lot Nathan. It works both ways and it works great.

Excellent answer

"Nathan Sokalski" wrote:
One thing you can use is the ItemDataBound event, which is fired after each
event. Also, if you are simply going to append data from the datasource
(which is what it looks like you are doing for the ImageUrl attribute, try
this overload of the DataBinder.Eval method:

ImageUrl='<%#
DataBinder.Eval(Container,"DataItem.NeedForCover", "images/{0}.BMP") %>'

This code would return a string such as:

ImageUrl='images/yourimagename.BMP'

It basically replaces the {0} with the specified DataItem field.
If you have more complex strings you want to create, you can do that using
the ItemDataBound event. Here is an example of how to do the same thing
using this event:

Private Sub datMembers_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataListItemEventArgs) Handles
datMembers.ItemDataBound
CType(e.Item.FindControl("imgYourImageID"),
System.Web.UI.WebControls.Image).ImageUrl="images/" &
e.Item.DataItem("NeedForCover") & ".BMP"
End Sub

Obviously you can use any type of code you want in this event, including
conditional statements. This event is triggered after the individual Item
has been databound, so it can also be used to check what value was assigned
from the datasource (sometimes you want to check for a value of "" or maybe
replace "" with " " or a default value, or any number of other things
you may want to do). Hopefully you can solve your problems using these
techniques, if you need more help feel free to ask. Good Luck!
--
Nathan Sokalski
nj********@hotmail.com
http://www.nathansokalski.com/

"Gentian" <Ge*****@discussions.microsoft.com> wrote in message
news:E7**********************************@microsof t.com...
I have a datalist bound to a dataset.

In the Items template I have a Image which was supposed to changed
depending
on a certain value retrieved from the dataset.

I have the ImageUrl attribute for the Image which I want to change

ImageUrl='...images\' <%# DataBinder.Eval(Container,
"DataItem.NeedForCover")%>'.BMP'> but it complains: the server tag is not
well formed. All I want to get from the dataset is the string.

How can I make it work ?

Also is there a way to put some kind of condition before an attribute like
we did with ASP f.e:

<%#if DataBinder.Eval(Container, "DataItem.NeedForCover")=True then %>
ImageUrl='...\images\HAPPY.BMP'>
<%# else %>
ImageUrl='...\images\SAD.BMP'>
<%# End if %>

Please help,

Thank everyone.


Feb 10 '06 #3

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

Similar topics

1
by: CodeRazor | last post by:
Hi, I've working with a web app someone else has written. It contains inline code. For example: <html><body topmargin="0"> <%If Session("mySession") = "bla" Then%> // html code in here <%End...
30
by: Will Pittenger | last post by:
Does C# inline functions? I do not see a inline keyword. Is there an implicit inline? Can the compiler select functions for auto-inlining? I am more used to C++ where all these things are...
1
by: JWhitted | last post by:
I created a control which parses its sub objects and wraps the code in an HTML wrapper. For example: <abc:Section ID="Section1" Runat="server" Title="Example"> <p>This is an example.</p>...
2
by: Newbie \(C#,Asp.net\) | last post by:
Hi I have two simple questions that I make sure that I have underestood them 1) what is the main difference between inline coding and code behind besides that code behind is part of DLL and is...
4
by: Ken McCrory | last post by:
I have a page with some inline server-side code. An example line is: <input type="hidden" name="fmFirstName" value="<%=Session("FirstName")%> "> The code and logic works and does what it is...
8
by: neilmcguigan | last post by:
I just wanted to list some reasons why I prefer inline code to code-behind. 1. you can fix some bugs more quickly. remote desktop into server, change the aspx file, and she's good to go. I'd say...
1
by: Dave | last post by:
I have the following ASP.NET 2.0 code (simplified here for ease): <asp:Repeater id="SearchResultsRepeater" runat="server"> <ItemTemplate> <uc:SearchResult ID="SearchResult"...
3
by: AleXmanFree | last post by:
Hi , I have got problem with passing my inline based value to y user control (or custom control, no matter which one I use, I have tried both to make sure it doesnt matter) . So say I have...
1
by: AleXmanFree | last post by:
Hi , I have got problem with passing my inline based value to y user control (or custom control, no matter which one I use, I have tried both to make sure it doesnt matter) . So say I have...
5
by: sunil | last post by:
Hello, I have a class deriving from a class that provides ability to serialize/deserialize objects over the network. There are two classes Requests (sent from client to server) Response(sent from...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.