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?

有帮助吗?

解决方案

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

其他提示

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.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top