我想将图像添加到我的aspx类中的表中的特定单元格。现在我有一个if语句改变了单元格的颜色,我想要另一个if语句,它将图像添加到同一个单元格。任何想法如何做到这一点?
public partial class FutureDelivery : System.Web.Mvc.ViewPage
{
protected void Page_Load(object sender, EventArgs e)
{
// Response.Cache.SetCacheability(HttpCacheability.NoCache);
errormsg.Text = "";
FutureDeliveryModel theModel = (FutureDeliveryModel)ViewData["FutureDelivery"];
// litSite.Text = Site.getSite();
//DataTable StockTable = (DataTable)ViewData["Future"];
DataTable StockTable = theModel.GetFuture();
DataView StockView = StockTable.DefaultView;
StringBuilder SB = new StringBuilder();
SB.Append("<table class=\"display\" id=\"dt\" style=\"align: left; width: 99%;\" ");
SB.Append("rules=\"all\" border=\"1px\" ");
SB.Append("cellspacing=\"0px\" cellpadding=\"4px\">");
SB.Append("<thead>");
SB.Append("<tr></tr>");
SB.Append("<tr style=\"background-color: Silver; color: #212121; ");
SB.Append("font-weight: bold\">");
// Header
foreach (DataColumn aColumn in StockTable.Columns)
{
SB.Append("<td>");
SB.Append(aColumn.ColumnName);
SB.Append("</td>");
}
SB.Append("</tr>");
SB.Append("</thead>");
SB.Append("<tbody>");
string Site = " ";
//detail
foreach (DataRowView aRowView in StockView)
{
int qty = 0;
int export = 0;
SB.Append("<tr>");
foreach (DataColumn aColumn in StockTable.Columns)
{
SB.Append("<td style=\"text-align: left\"");
if (aColumn.ColumnName.ToString().Equals("Site"))
{
// SB.Append("<a href=\"");
// SB.Append(ApplicationUtility.FormatURL("/Stock/FutureDelivery"));
// SB.Append("?Site=");
SB.Append(">");
Site = aRowView["Site"].ToString();
SB.Append(Site);
// SB.Append(aRowView[aColumn.ColumnName].ToString());
// SB.Append("</a>");
}
else
{
if (aColumn.ColumnName.ToString().Equals("Quantity")) qty = Convert.ToInt32(aRowView["Quantity"].ToString());
if (aColumn.ColumnName.ToString().Equals("Export Quantity"))
{
export = Convert.ToInt32(aRowView["Export Quantity"].ToString());
if (export != qty && export != 0) SB.Append(" BGCOLOR=\"#00ff00\" ");
}
SB.Append(">");
if (aColumn.ColumnName.ToString().Equals("Export Quantity"))
{
if (export == 0)
{
SB.Append(" ");
}
else
{
SB.Append(aRowView[aColumn.ColumnName].ToString());
}
}
else
{
SB.Append(aRowView[aColumn.ColumnName].ToString());
}
}
SB.Append("</td>");
}
SB.Append("</tr>");
}
SB.Append("</tbody>");
SB.Append("</table>");
litFutureDeliveryDetail.Text = SB.ToString();
linkBackToMainPage.NavigateUrl = ApplicationUtility.FormatURL("/Stock/Login?action=out");
linkBack.NavigateUrl = (String)Session["BACKURL"];
linkUserMaint.NavigateUrl = ApplicationUtility.FormatURL("/Stock/UserMaint");
screentitle.Text = "Future Deliveries";
if (theModel.GetErrorMessage().Trim() != "")
{
StringBuilder ES = new StringBuilder();
ES.Append("<table border=1><tr><td class=\"ErrorText\">");
ES.Append(theModel.GetErrorMessage().ToString());
ES.Append("</td></tr></table>");
errormsg.Text = ES.ToString();
}
else
{
errormsg.Text = " ";
}
}
}
}
答案 0 :(得分:0)
可能你只需要一个字符串追加,如下,
if(condition){
sb.Append("<img src=\"images/pic.jpg\" alt=\"Sample Photo\" />");
}
images/pic.jpg
是图像的路径。