我是新來的asp.net。我在該網頁中創建了一個網頁,我使用表格標籤設計了該網頁。我已經在文件後面的代碼中填充了數據表。我訪問了網頁設計中的數據表字段,以便在表格中顯示值。用於訪問值的代碼是作爲follows--如何在asp.net中的網頁文件後面的代碼中調用設計頁面中的函數?
<table>
<tr>
<td class="FieldHeader">
<span>MD Priority :</span></td>
<td>
<span><img src='<%GetImage(dtCompany.Rows[0]["MDPriority"]);%>' alt=""/>
<%Response.Write(dtCompany.Rows[0]["MDPriority"].ToString());%>
</span>
</td>
</tr>
</table>
的getImage函數的格式follows--
public string GetImage(object ImageID)
{
if (ImageID != null | ImageID != DBNull.Value)
{
int imageID = 0;
if (ImageID != DBNull.Value)
{
imageID = Convert.ToInt32(ImageID);
}
switch (imageID)
{
case 0:
strPath = "../images/not assigned.jpg";
break;
case 1:
strPath = "../images/low.jpg";
break;
case 2:
strPath = "../images/midium.jpg";
break;
case 3:
strPath = "C:/Inetpub/wwwroot/VinserverWebTemplate2/images/high.jpg";
break;
case 4:
strPath = "../images/not assigned.jpg";
break;
}
return strPath;
}
else
{
return "";
}
}
我想要通過使用上述函數,以顯示圖像。但我無法在img標籤的src屬性中獲取圖像路徑。
當我運行我的網頁,然後下面的HTML代碼由browser--
<table>
<tr>
<td class="FieldHeader">
<span>MD Priority :</span></td>
<td>
<span><img src='' alt=""/>
1
</span>
</td>
</tr>
</table>
呈現怎樣解決這個問題?
謝謝。
您試圖執行比實際ASP.NET更多的舊式ASP代碼。當你看ASP.NET的時候,你需要明白這一點。 – Icarus
一個問題至少是你使用的是一個按位運算符而不是OR運算符: 'if(ImageID!= null | ImageID!= DBNull.Value)'應該是if(ImageID!= null || ImageID!= DBNull.Value)' – Shad
@ Shad:你是對的,但我認爲這不是不顯示圖像的原因。 – Priyanka