我想分别在Panel_video_1,Panel_video_2和Panel_video_link1,Panel_video_link2中添加图片和超链接,但是我的代码将所有图片和超链接都放到Panel.I我想在单独的面板中添加这些控件。
代码背后的代码:String sql1 ="SELECT title, video_id ,image_path FROM up_video WHERE Video_types='Song Video' ";
adpt = new SqlDataAdapter(sql1, cn);
ds = new DataSet();
adpt.Fill(ds, "title");
var lastUploaded = ds.Tables["title"].AsEnumerable().OrderByDescending(r => r.Field<int>("video_id")).Take(3);
foreach (DataRow row in lastUploaded)
{
int videoID = row.Field<int>("video_id");
Image img = new Image();
img.ID = "image" + videoID;
string title = row.Field<string>("title");
img.ImageUrl = row.Field<string>("image_path");
img.Height = 150;
img.Width = 150;
HyperLink hl = new HyperLink();
hl.ID = "hyperlink" + videoID;
string linktitle = row.Field<string>("title");
hl.Text = linktitle;
hl.NavigateUrl = "Downloadpage.aspx?name=" + linktitle;
hl.ForeColor = System.Drawing.Color.White;
Panel_video_1.Controls.Add(img);
Panel_Video_link1.Controls.Add(hl);
Panel_video_2.Controls.Add(img);
Panel_video_link2.Controls.Add(hl);
Panel_video_3.Controls.Add(img);
Panel_video_link3.Controls.Add(hl);
}
答案 0 :(得分:2)
一个image / hyperlink
对象只能添加到一个panel
,当您添加到第二个时,它会从第一个删除,依此类推。您必须创建三个图像对象并添加到三个面板。