2013-04-13 84 views
2

我想添加圖像和超鏈接分別在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); 
     } 

回答

2

一個image/hyperlink對象可以被添加到只有一個panel。您必須創建三個圖像對象並添加到三個面板。

+0

+1:這就是答案。 –