0
我有一個用戶控件具有一些屬性。如何獲得用戶控制數據動態加載時
public partial class ImageUpload : System.Web.UI.UserControl
{
public Image img = new Image();
protected void Page_Load(object sender, EventArgs e)
{
img.PG_Caption = txtImgCaption.Text;
img.PG_Visible = chkVisible.Checked;
img.File = fileImgUpload.FileBytes;
img.PG_FileName = fileImgUpload.FileName;
}
}
在另一個用戶控件上,我在page_load上加載了一些第一個用戶控件。
public partial class ImagesTab : System.Web.UI.UserControl
{
public int Count { get; set; }
public List<Image> Images
{
get { return GetImages(); }
}
private List<Image> GetImages()
{
List<Image> lI = new List<Image>();
foreach (Control ctl in plhImages.Controls)
{
}
return lI;
}
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
for (int i = 0; i < Count; i++)
{
Control ImageUpload = LoadControl("ImageUpload.ascx");
plhImages.Controls.Add(ImageUpload);
Literal li = new Literal();
li.Text = "<br />";
plhImages.Controls.Add(li);
}
}
}
}
如何在GetImages()上實現foreach循環來獲取數據?
似乎我在回發後沒有控件。 – eyalb 2011-03-30 15:20:00
@eyalb:你在哪裏使用'GetImage()'方法? – 2011-03-31 12:22:37