Problems with properties on WebUserControl and Repeater

  • Thread starter Michael Groeger
  • Start date
M

Michael Groeger

Hi,

I have created a little WebUserControl "SelectTemplate.ascx" which defines a
property

public class SelectTemplate : System.Web.UI.UserControl
{
public int PublisherType
{
get;
set;
}
}

On my form, I want to have a repeater which creates for each value in a
collection of "Publisher" items (=DataSource) a SelectTemplate control and
set the PublisherType property to the value of the corresponding property in
a Publisher.

public class Publisher
{
public int PublisherType
{
get;
set;
}
}

I added a repeater to my form and changed to code behind to edit Page_Load
as followed:
public void Page_Load(object sender, System.EventArgs e)
{
if (!IsPostBack)
{
Repeater1.DataSource = _Publishers; // _Publishers actually is
stored in the session state
Repeater1.DataBind();
}
}

Then I switched to html view and edited the InnerTemplate of the repeater:
<asp:Repeater id="Repeater1" runat="server">
<ItemTemplate>
<uc1:SelectTemplate id="SelectTemplate1" runat="server"
PublisherType="<%# DataBinder.Eval(Container.DataItem, "PublisherType"
%>"></uc1:SelectTemplate>
</ItemTemplate>
</asp:Repeater>

Unfortunateley, when executing the code, I get the following - quite
uninformational error:
Parser-Error: Servertag not formatted property

Sorry, I am having german version of .NET installed, so I had to translate
to english. The german message sounds as follows:
Parser-Fehlermeldung: Servertag wurde falsch formatiert.

Can somebody help me out?

Regards,
Michael
 
W

William F. Robertson, Jr.

I think there is a problem with you " around publisher type in your
ItemTemplate definition

PublisherType="<%# DataBinder.Eval(Container.DataItem, "PublisherType" %>">

Try using

PublisherType='<%# DataBinder.Eval(Container.DataItem, "PublisherType" %>'>

Notice I changed the outer quotes to a single quote.

bill

Dein English ist sehr gut!
 
M

Michael Groeger

Hi Bill,
Try using

PublisherType='<%# DataBinder.Eval(Container.DataItem, "PublisherType"
%>'>

Correct! Now it works, thank you.
Dein English ist sehr gut!
Thank you ;) Does this mean that I translated the german text properly or do
you mean my english at all? ;)

Regards,
Michael
 

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

Top