Question

I've been into web for long, but now I should do a little c# project and I'm wondering how I can make such repeat:

enter image description here

In web I can just do

<div id="holder">
    <div class="item"></div>
    <div class="item"></div>
    <div class="item"></div>
</div>

and even add it dynamicly:

var items = [{}, {}, {}, {}];
for ( var i in items ) {
     $("#holder").append("<div class=\"item\"></div>");
}

and render as much items as represented in the array.

My actual question is how to use exactly User Control?

Was it helpful?

Solution

You can create a UserControl (Add > New Item... > User Control)

public partial class WFUserControl : UserControl
{
}

user control

And add on a container control, such as a panel

panel1.Controls.Add(new WFUserControl());

To make it add one bellow another you can use a TableLayoutPanel, set AutoSize to true, set only one column and only one row. Then when you add 3 controls it will look like this:

table layout panel

OTHER TIPS

Actually, it is according to your need but let's say you want to repeat the same template for items that you have pulled from database, you can use data list or list view.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top