Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using web user control in a repeater 1

Status
Not open for further replies.

wawalter

Programmer
Aug 2, 2001
125
0
0
US
Hello,

I am trying to use a web user control I created in a repeater. I can get the control to display in the repeater but, the problem I am having is none of the properties I set when creating the control display on the page. The properties work if I create a single instance of the control without using the repeater. I am binding a collection of my object to the repeater.

Code:
List<ZFMailerControl> zfMailerControls = new List<ZFMailerControl>();

// create controls and initialize the properties from datareader then add to List
while (dr.Read())
{
   ZFMailerControl zfmc = new ZFMailerControl();
   zfmc.ProductName = "test this " + counter.ToString();
   zfMailerControls.Add(zfmc);
   counter++;
}

// bind the List to the repeater
rptMailer.ItemTemplate = LoadTemplate ("ZFMailerControl.ascx");
rptMailer.DataSource = zfMailerControls;
rptMailer.DataBind();

I'd appreciate any help or if there is a better way to do this please let me know.

Thanks,
Bill
 
I see what your trying to do. Repeater doesn't work that way. instead you want to define your repeater template to contain your user control. then bind your values.
Code:
<asp:repeater runat="server" ... DataSourceId="myDataSource">
  <HeaderTemplate />
  <ItemTemplate>
    <userControl:MyControl runat="server" ProductName='Bind("myColumn")'/>
  </ItemTemplate>
  <FooterTemplate />
</asp:repeater>
<asp:[DataSourceControl] SQL | Object | OLE runat="server" ID="myDataSource">
...
<asp:[DataSourceControl]>

Jason Meckley
Programmer
Specialty Bakers, Inc.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top