PC Review


Reply
Thread Tools Rating: Thread Rating: 8 votes, 4.00 average.

<%# DataBinder.Eval(Container.DataItem, "FirstName") %> in a fieldof a web server control ?

 
 
abargaddon
Guest
Posts: n/a
 
      28th Jan 2008
Hello everybody,
I need to use bound variables in a field of a web server control which
is inside a template. Many sources in the Web say it works, but for me
it does not, so I have made a test page :

<%@ Page Language="C#" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<script runat="server">

public class Bidon
{
public string OwnerId { get { return "111"; } }
public string FirstName { get { return "Alberto"; } }
}

protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
System.Collections.Generic.List<Bidon> listBidon =
new System.Collections.Generic.List<Bidon>();
listBidon.Add(new Bidon());
listBidon.Add(new Bidon());
RepeaterCollection.DataSource = listBidon;
RepeaterCollection.DataBind();
}
}

</script>

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ptitle</title>
</head>
<body>
<form id="form1" runat="server">
<h2>
Test Repeater and templates</h2>
<asp:Repeater ID="RepeaterCollection" runat="server">
<ItemTemplate>
ItemTemplate : <%# DataBinder.Eval(Container.DataItem,
"OwnerId") %>
- <%# DataBinder.Eval(Container.DataItem, "FirstName") %>
<asp:HyperLink ID="HyperLink2" runat="server"
Text='eval (<%# DataBinder.Eval(Container.DataItem,
"OwnerId") %>)' />
<asp:Label ID="Label2" runat="server"
Text='eval (<%# DataBinder.Eval(Container.DataItem,
"FirstName") %>)' />
<br />
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>


The result I obtain is below : Eval() does not work inside the asp:label
or the asp:hyperlink Text fields :

Test Repeater and templates
ItemTemplate : 111 - Alberto eval () eval ()
ItemTemplate : 111 - Alberto eval () eval ()

Can anyone help me please ?

Sincerely,
Abargaddon
 
Reply With Quote
 
 
 
 
Milosz Skalecki [MCAD]
Guest
Posts: n/a
 
      29th Jan 2008
Howdy,

In AP.NET 2.0 you can use Eval instead of DataBinder.Eval. In addition
remember data bound expressions for server controls must be defined in entire
attribute:
<asp:Label runat="server" Text='<%# "prefix " + Eval("whatever") %>'/>
NOT
<asp:Label runat="server" Text='prefix<%# Eval("whatever") %>'/>

Anyway:
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Ptitle</title>
</head>
<body>
<form id="form1" runat="server">
<h2>
Test Repeater and templates</h2>
<asp:Repeater ID="RepeaterCollection" runat="server">
<ItemTemplate>
ItemTemplate : <%# DataBinder.Eval(Container.DataItem,
"OwnerId") %>
- <%# DataBinder.Eval(Container.DataItem, "FirstName") %>
<asp:HyperLink ID="HyperLink2" runat="server" Text='<%#
DataBinder.Eval(Container.DataItem, "OwnerId") %>' />
<asp:Label ID="Label2" runat="server" Text='<%#
String.Format(DataBinder.Eval(Container.DataItem, "FirstName"), "Surrounding
{0} text" %>' />
<asp:Label ID="Label3" runat="server" Text='<%# Eval("FirstName") %>'
<br />
</ItemTemplate>
</asp:Repeater>
</form>
</body>
</html>

Hope it helps
--
Milosz


"abargaddon" wrote:

> Hello everybody,
> I need to use bound variables in a field of a web server control which
> is inside a template. Many sources in the Web say it works, but for me
> it does not, so I have made a test page :
>
> <%@ Page Language="C#" %>
> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
> "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
> <script runat="server">
>
> public class Bidon
> {
> public string OwnerId { get { return "111"; } }
> public string FirstName { get { return "Alberto"; } }
> }
>
> protected void Page_Load(object sender, EventArgs e)
> {
> if (!this.IsPostBack)
> {
> System.Collections.Generic.List<Bidon> listBidon =
> new System.Collections.Generic.List<Bidon>();
> listBidon.Add(new Bidon());
> listBidon.Add(new Bidon());
> RepeaterCollection.DataSource = listBidon;
> RepeaterCollection.DataBind();
> }
> }
>
> </script>
>
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Ptitle</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <h2>
> Test Repeater and templates</h2>
> <asp:Repeater ID="RepeaterCollection" runat="server">
> <ItemTemplate>
> ItemTemplate : <%# DataBinder.Eval(Container.DataItem,
> "OwnerId") %>
> - <%# DataBinder.Eval(Container.DataItem, "FirstName") %>
> <asp:HyperLink ID="HyperLink2" runat="server"
> Text='eval (<%# DataBinder.Eval(Container.DataItem,
> "OwnerId") %>)' />
> <asp:Label ID="Label2" runat="server"
> Text='eval (<%# DataBinder.Eval(Container.DataItem,
> "FirstName") %>)' />
> <br />
> </ItemTemplate>
> </asp:Repeater>
> </form>
> </body>
> </html>
>
>
> The result I obtain is below : Eval() does not work inside the asp:label
> or the asp:hyperlink Text fields :
>
> Test Repeater and templates
> ItemTemplate : 111 - Alberto eval () eval ()
> ItemTemplate : 111 - Alberto eval () eval ()
>
> Can anyone help me please ?
>
> Sincerely,
> Abargaddon
>

 
Reply With Quote
 
 
 
 
abargaddon
Guest
Posts: n/a
 
      2nd Feb 2008
Hi Milosz,

Thank you a lot, this was indeed my problem.
However, I did not find it mentioned in the MSDN site, although it is an
important detail !

Thank you again, and have a nice sunday.
Abargaddon



Milosz Skalecki [MCAD] a écrit :
> Howdy,
>
> In AP.NET 2.0 you can use Eval instead of DataBinder.Eval. In addition
> remember data bound expressions for server controls must be defined in entire
> attribute:
> <asp:Label runat="server" Text='<%# "prefix " + Eval("whatever") %>'/>
> NOT
> <asp:Label runat="server" Text='prefix<%# Eval("whatever") %>'/>
>
> Anyway:
> <html xmlns="http://www.w3.org/1999/xhtml" >
> <head runat="server">
> <title>Ptitle</title>
> </head>
> <body>
> <form id="form1" runat="server">
> <h2>
> Test Repeater and templates</h2>
> <asp:Repeater ID="RepeaterCollection" runat="server">
> <ItemTemplate>
> ItemTemplate : <%# DataBinder.Eval(Container.DataItem,
> "OwnerId") %>
> - <%# DataBinder.Eval(Container.DataItem, "FirstName") %>
> <asp:HyperLink ID="HyperLink2" runat="server" Text='<%#
> DataBinder.Eval(Container.DataItem, "OwnerId") %>' />
> <asp:Label ID="Label2" runat="server" Text='<%#
> String.Format(DataBinder.Eval(Container.DataItem, "FirstName"), "Surrounding
> {0} text" %>' />
> <asp:Label ID="Label3" runat="server" Text='<%# Eval("FirstName") %>'
> <br />
> </ItemTemplate>
> </asp:Repeater>
> </form>
> </body>
> </html>
>
> Hope it helps

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Problem with web server control placed on web user control okaminer Microsoft ASP .NET 2 8th Feb 2005 04:34 PM
accessing the web user control's control from a web page and set a value from another web page Reny J Joseph Thuthikattu Microsoft ASP .NET 1 30th Dec 2004 01:21 PM
Showing 1 control inside a 2nd control where the 2nd control is a derived control. malcolm Microsoft Dot NET Framework Forms 0 10th Jun 2004 10:29 PM
HTML Client Control versus. HTML Server Control versus. Web Server Control Matthew Louden Microsoft VB .NET 1 11th Oct 2003 08:09 PM
HTML Client Control versus. HTML Server Control versus. Web Server Control Matthew Louden Microsoft ASP .NET 1 11th Oct 2003 08:09 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:55 PM.