views:

444

answers:

2

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

A: 

Repeaters are easily binded to datasources.

Fabian Vilers
A: 

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

thanks man, this kind of answers wanted to seei'll take a look at the listview. But when I look at examples of repeaters I cant see it that easy if repeated control is complicated with several events, properties...
Misha N.
u r welcome man, will everything can get as complex as you want it to be, but usually you can access all controls properties and events inside any databound control by using the Ondatabound, Onitem create, etc events of the listview, Grid, etc.. then from there you use find control and cast it