Need to build a repeater purely in code

C

Cappy

Hi.

I need help adding a repeater to my custom control in code.

I have created a custom control that draws a html panel to the screen.

I want to add a menu in the panel which will basically be a repeater
reading from an xml file.

so far I have this

protected override void CreateChildControls()
{
//Clear control state
Controls.Clear();

//make sure file name has been provided

//get data from xml file
//map the path to the menu xml file
string filePath = HttpContext.Current.Request.MapPath(_menufilePath);

//read xml file into DS
DataSet MenuDS = new DataSet();
MenuDS.ReadXml(filePath);

//create a new Repeater control and assign its
//data source
Repeater r = new Repeater();
r.DataSource = MenuDS;

//Stuck here
//How do I define my template and bind data to it

r.DataBind();

//add the Repeater control to the collection
Controls.Add(r);

//indicate that we have created child controls
ChildControlsCreated=true;
}


The above code works fine.. but now I need to know how to hard code
the template for the repeater and how to bind the data to it.

Can anyone help?

The xml file contains the following structure
<MenuItems>
<Item>
<Name>Homepage</Name>
<URL>/index.aspx</URL>
<Alt>Return to homepage</Alt>
<Image>/images/navLocationOff.jpg</Image>
<MouseOver>/images/navLocationOn.jpg</MouseOver>
</Item>
<Item>
<Name>NextLink</Name>
<URL>/index.aspx</URL>
<Alt>Go somewhere else</Alt>
<Image>/images/navLocationOff.jpg</Image>
<MouseOver>/images/navLocationOn.jpg</MouseOver>
</Item>
</MenuItems>

Thanks
Amit
 

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

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top