R – ASP.NET Repeater control or custom implementation

asp.netrepeateruser-controls

Hallo,

Recently I have read a couple of posts on varous sites and blogs that ASP.NET Repeater one of the most commonly used and accepted between experienced programmers.
Someone actually wrote that he consider the asp.net programmer better if he mentions that he often use this control in a job interview.
The fact that I used it rarely maybe makes me a beginner 🙂
This is implementation I have used when I needed some control repeated dynamically.

public class MyUserControl:UserControl
{
    LocalizedCheckBox chb;
    LocalizedLabel lbl;
    TextBox txt;


    public MyUserControl()
    {
        //Instantiate controls
    //do something with them
}

public bool Checked
{
    get{ return chb.Checked;}
}
public string Text
{
    get{ return txt.Text; }
}
}


public partial class MyParentControl : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        //           
    }
protected override void OnInit(EventArgs e)
    {
        base.OnInit(e);

    foreach('something')
    {
        MyUserControl ctr = new MyUserControl();
        ctr.Text="some value";
        ctr.Checked= false;
        this.Panel1.Controls.Add(ctr);
    }
    }
protected void btn_Click(object sender, EventArgs e)
    {
        foreach (MyUserControl dControl in this.Panel1.Controls.OfType<MyUserControl>())
        {
            //do something
    string text = dControl.Text;
        }
    }
}

I have never had a problem with this code even when I added the events on MyUserControl. Of course, that it's possible to achieve the same with repeater control, but I would like to know why(or is it) better to use repeater.

What are the benefits if I use repeater instead?

Thanks

Best Answer

man, you better use repeater or much better use listvew in Net 3.5, why ? -because it is super easy to databind to any datasource, using Eval for controls inside of it. - you get many templates for your like , i use it a lot when the database return no result, you can put a message here to inform the user instead of showing blank screen. - you can control the rendering, whither you want Tables, Div, UL, you just name it.

i highly recommend to invest in the new listview for repeating stuff.

hope this helps

Related Topic