2011-08-04 66 views
1

我必須通過其標籤(即超鏈接)動態創建圖像。爲此,我編寫了如下代碼,但不顯示圖像,它只顯示標籤(超鏈接)。如何使用asp.net中的標籤動態創建圖像c#

string fname=""; 
     string fpath = ""; 
     DataSet dsfile = new DataSet(); 
//For fetching data that is inserted earlier in database 

     SqlDataAdapter dafile = new SqlDataAdapter("select FileName,FilePath from CRM_CustomerAttachment where CustomerID='" + cust + "'", FlyCon); 
     dafile.Fill(dsfile); 
     if (dsfile != null) 
     { 
      fname = Convert.ToString(dsfile.Tables[0].Rows[0]["FileName"]); 
      fpath = Convert.ToString(dsfile.Tables[0].Rows[0]["FilePath"]); 
     } 

     PlaceHolder PHFilename = (PlaceHolder)FVViewCustData.FindControl("PHFilename");//FVViewCustData is formview & placeholder is inside the formview 
     for (int i = 0; i < dsfile.Tables[0].Rows.Count; i++) 
     { 
      HyperLink hypname = new HyperLink(); 
      hypname.Text = Convert.ToString(dsfile.Tables[0].Rows[i]["FileName"]) + "</br>"; 
      PHFilename.Controls.Add(hypname); 
      Image img = new Image(); 
      img.ImageUrl = Convert.ToString(dsfile.Tables[0].Rows[i]["FilePath"]);   
      PHFilename.Controls.Add(img); 
    } 

Asp.net C#。 請幫幫我嗎?謝謝。

+0

你檢查的路徑是正確與否?大多數情況下圖像不顯示,因爲路徑錯誤 –

+0

它顯示紅色十字? – V4Vendetta

回答

0

她是代碼

Dim img As New Image 
     img.ID = "img1" 
     img.ImageUrl = "http://www.prodeveloper.org/wp-content/uploads/2008/10/stackoverflow-logo-250.png" 
     PlaceHolder1.Controls.Add(img) 
+0

路徑是否正確到這裏我添加我的IP地址加上我的文件夾名稱加上該字符串(Convert.ToString(dsfile.Tables [0] .Rows [i] [「FilePath」]))然後它也不顯示什麼是錯誤的那? – abc

+0

是啊,但在你的代碼中的超鏈接和圖像的ID? –

+0

我使用Dim img As New Image img.ID =「img1」 img.ImageUrl =「http://www.prodeveloper.org/wp-content/uploads/2008/10/stackoverflow-logo-250.png」 PlaceHolder1.Controls.Add(img) –

相關問題