Server control derived from Repeater?

Discussion in 'ASP .Net' started by Dobedani, Nov 26, 2003.

  1. Dobedani

    Dobedani Guest

    Dear All,

    I would like to use a Repeater to show data - mostly large volumes
    from a database - in a comma delimited format. VS.NET documentation
    mentions this as one of the uses of the Repeater! Actually, the idea
    is that users can save the output of a request as CSV file on their
    desktop. For that reason, I stripped my aspx of all html and left only
    the first line:
    <%@ Page language="c#" Codebehind="csv.aspx.cs" etc. %>

    I hope to be able to add the repeater on the fly, like in the
    following:
    Repeater rptData = new Repeater();
    this.Controls.Add(rptData);

    However, it appears impossible to edit the templates in the code. I
    tried assigning strings to the HeaderTemplate and ItemTemplate, but I
    got:
    Cannot convert type 'string' to 'System.Web.UI.ITemplate' even when I
    tried to cast my strings.

    I am now thinking that to create a server control derived from
    Repeater is the way forward. Am I right? How to go about it? And what
    should the ItemTemplate look like? I hope to avoid databinding with
    DataBinder.Eval because that will make the page terribly slow.
    Moreover, the number of columns is variable (max. 13). I hope somebody
    can help me. TIA

    Kind regards,
    Dobedani
    Wageningen
    The Netherlands
    Dobedani, Nov 26, 2003
    #1
    1. Advertising

  2. Dobedani

    Tommy Guest

    I have never tried adding columns to a repeater control dynamically,
    but I have done this with a datagrid control, and I think the
    technique whould be very similar.

    1. You need to create a class that implments ITemplate
    2. In this class, implement InstantiateIn.
    InstantiateIn allows you to
    a. Modify the template to contain any control you like
    b. Attach a handle the databinding event.
    3. Create a method that will handle the databinding event, such as
    HandlingDataBinding
    4. In the HandlingDataBinding method, you can add the data from your
    data source to your controls.
    5. For each column you need in the repeater control, add an instance
    of the
    class you've created above.

    Tommy,

    (Dobedani) wrote in message news:<>...
    > Dear All,
    >
    > I would like to use a Repeater to show data - mostly large volumes
    > from a database - in a comma delimited format. VS.NET documentation
    > mentions this as one of the uses of the Repeater! Actually, the idea
    > is that users can save the output of a request as CSV file on their
    > desktop. For that reason, I stripped my aspx of all html and left only
    > the first line:
    > <%@ Page language="c#" Codebehind="csv.aspx.cs" etc. %>
    >
    > I hope to be able to add the repeater on the fly, like in the
    > following:
    > Repeater rptData = new Repeater();
    > this.Controls.Add(rptData);
    >
    > However, it appears impossible to edit the templates in the code. I
    > tried assigning strings to the HeaderTemplate and ItemTemplate, but I
    > got:
    > Cannot convert type 'string' to 'System.Web.UI.ITemplate' even when I
    > tried to cast my strings.
    >
    > I am now thinking that to create a server control derived from
    > Repeater is the way forward. Am I right? How to go about it? And what
    > should the ItemTemplate look like? I hope to avoid databinding with
    > DataBinder.Eval because that will make the page terribly slow.
    > Moreover, the number of columns is variable (max. 13). I hope somebody
    > can help me. TIA
    >
    > Kind regards,
    > Dobedani
    > Wageningen
    > The Netherlands
    Tommy, Nov 27, 2003
    #2
    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. Replies:
    4
    Views:
    392
    Alf P. Steinbach
    May 23, 2007
  2. Replies:
    1
    Views:
    387
    myork
    May 23, 2007
  3. Replies:
    1
    Views:
    374
    Victor Bazarov
    May 23, 2007
  4. David
    Replies:
    3
    Views:
    392
    Grizlyk
    Jan 29, 2008
  5. alexb

    How create user control derived from Repeater

    alexb, May 16, 2004, in forum: ASP .Net Web Controls
    Replies:
    0
    Views:
    130
    alexb
    May 16, 2004
Loading...

Share This Page