Need to build a repeater purely in code

Discussion in 'ASP .Net Building Controls' started by Cappy, Feb 2, 2004.

  1. Cappy

    Cappy Guest

    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
    Cappy, Feb 2, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Dot net work
    Replies:
    1
    Views:
    541
    Scott Allen
    Jan 3, 2005
  2. Anil Kumar Narayanan
    Replies:
    1
    Views:
    468
    Peter van Merkerk
    Dec 18, 2003
  3. Jeffrey Froman

    Purely emotional perspective

    Jeffrey Froman, Aug 9, 2004, in forum: Python
    Replies:
    12
    Views:
    505
    Jeffrey Froman
    Aug 11, 2004
  4. Adam Tauno Williams
    Replies:
    21
    Views:
    623
  5. Replies:
    12
    Views:
    855
    Eric Schwartz
    Sep 30, 2004
Loading...

Share This Page