2

我想分别在 Panel_video_1、Panel_video_2 和 Panel_video_link1、Panel_video_link2 中添加图像和超链接,但我的代码将所有图像和超链接带到最后一个面板。我想在单独的面板中添加这些控件。

后面的代码:

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);
      }
4

1 回答 1

2

一个image / hyperlink对象只能添加到一个panel,当您添加到第二个时,它会从第一个中删除,依此类推。您必须创建三个图像对象并添加到三个面板。

于 2013-04-13T15:29:19.310 回答