That'll teach me to try in-line when I'm a code-behind man :) Your approach is definitely working, thanks!

Regards,
David P. Donahue
[EMAIL PROTECTED]



Carl Olsen wrote:
I'm not sure I understand the problem, but you should be able to define a
function and use it on the DataItem.  Say, for example, that I wanted to
change the color of the text depending on the value of the DataItem (say,
for example, true and false):

In the code behind page, I have this:

                protected System.Drawing.Color GetColorText(DateTime
resignationDate)
                {
                        DateTime todayDate = DateTime.Now;
                        if (resignationDate < todayDate)
                        {
                                return System.Drawing.Color.Pink;
                        }
                        else
                        {
                                return System.Drawing.Color.Teal;
                        }
                }

In my item template, I call the function, like this:

<asp:label runat="server" text='<%# DataBinder.Eval(Container.DataItem,
"MemberName") %>' font-bold="True" id="District2" width="100%"
forecolor='<%# GetColorText((DateTime)DataBinder.Eval(Container.DataItem,
"ResignationDate")) %>'/>

Does that help?

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] On Behalf Of David P. Donahue
Sent: Friday, June 03, 2005 5:25 PM
To: [email protected]
Subject: [Mono-list] Problem with DataBinder.Eval(Container.DataItem, "")

Not sure if this is a Mono thing or a .NET thing in general, but...

Normally, when I want to bind data to a DataList in ASP .NET, I just bind it to a DataSet and the HTML code contains things like:
<%# DataBinder.Eval(Container.DataItem, "Title") %>
This manages to display, for each record, the text contained in the field "Title" in the DataSet.

Now, I'm trying to add some more logic to that. As far as I know, I'd need to lose the # in the opening bracket and I can just write code as normal. This code should be in C# if that's what I use in my project, right? My first step before adding any other logic was to simply change the above to:
<% Response.Write(DataBinder.Eval(Container.DataItem, "Title")); %>
However, I get an error at runtime saying that the name "Container" can't be found in the class.

Is this by design? Is there another approach I should take? All I'm trying to do is add a simple conditional so, based on the contents of one field, it will either display another field or display a default. Simple enough.

Any ideas?


Regards,
David P. Donahue
[EMAIL PROTECTED]
_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list



_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list


_______________________________________________
Mono-list maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-list

Reply via email to