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
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