1
我在我的網格的最後一列的每個單元格中插入一個img控件。但圖像沒有顯示(出現X)。圖像不顯示在GridView中asp.net
我試着把一個html圖像放在頁面的其他地方,以確保圖像的路徑是正確的,並在該html圖像中出現圖片。當檢查頁面的view source
時,gridview中的html圖像和圖像都具有相同的ImageUrl
。
想知道這裏缺少什麼嗎?
圖像應在此插入:
<asp:BoundField DataField="RequestStatusId" HeaderText="Status"
ReadOnly="true" />
ASPX:
<asp:GridView ID="gvwRequests" runat="server" AutoGenerateColumns="False"
DataSourceID="odsRequests" AllowPaging="true" PageSize="10"
CssClass="GridStyle" onrowdatabound="gvwRequests_RowDataBound">
<Columns>
<asp:ButtonField HeaderText="Request" DataTextField="Request"
SortExpression="Request" CommandName="OpenRequest" />
<asp:BoundField DataField="RequestDate" HeaderText="RequestDate"
SortExpression="RequestDate" />
<asp:BoundField DataField="RequestNbr" HeaderText="RequestNbr"
SortExpression="RequestNbr" />
<asp:BoundField DataField="PartNumber" HeaderText="PartNumber"
SortExpression="PartNumber" />
<asp:BoundField DataField="Qty" HeaderText="Qty" SortExpression="Qty" />
<asp:BoundField DataField="Model" HeaderText="Model" SortExpression="Model" />
<asp:BoundField DataField="Brand" HeaderText="Brand" SortExpression="Brand" />
<asp:BoundField DataField="Customer" HeaderText="Customer"
SortExpression="Customer" />
<asp:BoundField DataField="RequestStatusId" HeaderText="Status"
ReadOnly="true" />
</Columns>
<AlternatingRowStyle CssClass="GridAlternateRowStyle" />
<RowStyle CssClass="GridRowStyle" />
<PagerStyle CssClass="GridPagerStyle" />
</asp:GridView>
aspx.cs
protected void gvwRequests_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
Image img = new Image();
string sColor = ListOfColorStatus.Find(item => item.RequestStatusId == Convert.ToInt32(e.Row.Cells[8].Text)).Color;
string sStatus = ListOfColorStatus.Find(item => item.RequestStatusId == Convert.ToInt32(e.Row.Cells[8].Text)).Status;
img.ImageUrl = "../images/" + sColor + "_ball.png";
img.AlternateText = sColor;
img.ToolTip = sStatus;
e.Row.Cells[8].Controls.Add(img);
}
}
來源:
<img src="../images/Yellow_ball.png" alt="Yellow" /> --> Appears
<div>
<table class="GridStyle" cellspacing="0" rules="all" border="1" id="ctl00_ContentPlaceHolder1_gvwRequests" style="border-collapse:collapse;">
<tr>
<th scope="col">Request</th><th scope="col">RequestDate</th><th scope="col">PONbr</th><th scope="col">PartNumber</th><th scope="col">Qty</th><th scope="col">Model</th><th scope="col">Brand</th><th scope="col">Customer</th><th scope="col">Status</th>
</tr><tr class="GridRowStyle">
<td><a href="javascript:__doPostBack('ctl00$ContentPlaceHolder1$gvwRequests','OpenRequest$0')">2</a></td><td>03-12-2015</td><td>22222</td><td>32151458121</td><td>5</td><td>BLACKBERRY 8520</td><td>RESEARCH IN MOTION</td><td>CABLE & WIRELESS ANTIGUA LTD</td><td><img title="Pending" src="../images/Yelow_ball.png" alt="Yelow" style="border-width:0px;" /></td> --> Does not appear
您可以將網站的目錄結構,所以我們可以看到這個頁面的相對路徑,圖片目錄 – CheGueVerra 2015-03-13 19:19:32
@CheGueVerra請參閱更新 – Somebody 2015-03-13 19:30:10
@有人看到我更新的答案... – Tim 2015-03-13 19:31:58