动态添加多个用户控件vb.net [英] Dynamically Adding Multiple User Controls vb.net

查看:140
本文介绍了动态添加多个用户控件vb.net的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用户控件,该控件返回一个数据表,在某些情况下,该数据表需要循环显示,一个显示在另一个之上.

I have a User Control which returns a table of data, which in some cases needs to be looped, displaying one on top of another.

通过在页面中放置固定的 placeholder ,我可以动态添加单个实例.

I am able to dynamically add a single instance of this by placing a fixed placeholder in the page.

由于我不知道可能需要多少个,所以我现在想找出如何添加多个的方法.我不想对占位符进行硬编码.

I am now trying to work out how to add more than one, given that I don't know how many might be needed I don't want to hard code the Placeholders.

我已经尝试了以下方法,但是我只是得到一个实例,大概第一个实例被第二个实例覆盖

I've tried the following, but I am just getting one instance, presumably the first is being overwritten by the second

我的HTML

<div id="showHere" runt="server"/>

VB

Dim thisPh As New PlaceHolder
thisPh.Controls.Add(showTable)
showHere.Controls.Add(thisPh)

Dim anotherPh As New PlaceHolder
anotherPh .Controls.Add(showTable)
showHere.Controls.Add(anotherPh)

如何使其在 showHere div中添加重复的表?

How do I make it add repeated tables within the showHere div?

推荐答案

我建议为每个表生成一个不同的ID.例如,

I would advise generating a different ID for each of your table. For example,

Dim i As Integer
i = 0
For each tbl in ShowTables
    tbl.ID = "MyTab" + i.ToString()
    i = i + 1
    showHere.Controls.Add(tbl)
    showHere.Controls.Add(New LiteralControl("<br />"))
Next

另一方面,让您的用户/自定义控件为单个表生成html,然后将您的用户/自定义控件嵌套在转发器(或类似的控件,如ListView等)中会更有意义.

On other hand, it would make more sense to have a your user/custom control generate html for a single table and then nest your user/custom control within a repeater (or similar control such as ListView etc).

这篇关于动态添加多个用户控件vb.net的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆