문제

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