我是C#的新手以及一般的编程。我有一个表是一个aspx Web表单页面,Ι想要显示一些图像。我通过上传特定文件夹中的文件然后将完整路径存储在数据库中来获取图像URL,并在页面加载时通过调用wcf服务从图像URL获取数据库。路径在数据库中成功更新,但图像未显示在我的页面上。我也尝试自己复制并粘贴路径,即使这样,图像也不会出现。我一直在寻找这个,但我仍然不知道它失败的原因。我尝试了jpg和gif图像。这是我的代码:
account.aspx
<asp:Table ID="Table1" runat="server" BorderStyle="dotted" BorderWidth="5" GridLines="vertical" HorizontalAlign="Center" Width="572px" style="margin-left: 0px">
<asp:TableRow >
<asp:TableCell Width="192">
<asp:Label ID="Label11" runat="server" Text="Στιγμιότυπο παραγγελίας:"></asp:Label>
</asp:TableCell>
<asp:TableCell Width="192">
<asp:Label ID="Label13" runat="server" Text="Χρονοδιάγραμμα:"></asp:Label>
</asp:TableCell>
<asp:TableCell Width="192">
<asp:Label ID="Label15" runat="server" Text="Τιμολόγιο:"></asp:Label>
</asp:TableCell>
</asp:TableRow>
<asp:TableRow>
<asp:TableCell>
<asp:Image ID="img_form_instance" ImageUrl="" runat="server" width="50" Height="50"/>
</asp:TableCell>
<asp:TableCell>
<asp:Image ID="img_timeschedule" ImageUrl="" runat="server" width="50" Height="50"/>
</asp:TableCell>
<asp:TableCell>
<asp:Image ID="img_invoice" ImageUrl="" runat="server" width="50" Height="50"/>
</asp:TableCell>
</asp:TableRow>
</asp:Table>
account.aspx.cs
protected void Page_Load(object sender, EventArgs e)
{
int id = (int)Session["UserId"];
try
{
clientInfo_Ref.IclientInfoClient clInfoClient = new clientInfo_Ref.IclientInfoClient();
List<string> rows = new List<string>(clInfoClient.getClientInfo(id));
string column = rows.FirstOrDefault();
if (String.IsNullOrEmpty(column))
{
//Do nothing
}
string[] columns = column.Split(';');
name_lbl.Text = columns[0];
sname_lbl.Text = columns[1];
address_lbl.Text = columns[2];
pc_lbl.Text = columns[3];
business_lbl.Text = columns[4];
fc_lbl.Text = columns[5];
pfs_lbl.Text = columns[6];
telephone_lbl.Text = columns[7];
fax_lbl.Text = columns[8];
mail_lbl.Text = columns[9];
}
catch
{
}
try
{
accountInfo_Ref.IaccountInfoSrvcClient accInfoClient = new accountInfo_Ref.IaccountInfoSrvcClient();
List<string> rows2 = new List<string>(accInfoClient.getAccountInfo(id));
string column2 = rows2.FirstOrDefault();
if (String.IsNullOrEmpty(column2))
{
//Do nothing
}
string[] columns2 = column2.Split(';');
//No need to display sensitive info in account page-> inclucde only safe column info
order_id_lbl.Text = columns2[1];
state_lbl.Text = columns2[2];
cost_lbl.Text = columns2[3];
img_form_instance.ImageUrl = columns2[4];
img_timeschedule.ImageUrl = columns2[5];
img_invoice.ImageUrl = columns2[6];
notificatin_lbl.Text = columns2[7];
}
catch (Exception)
{
}
}
答案 0 :(得分:0)
希望这样做了
// Replace absolute paths with relative ones
String form_relPath = columns2[4].Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
String schedule_relPath = columns2[5].Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
String invoice_relPath = columns2[6].Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty);
//No need to display sensitive info in account page-> inclucde only safe column info
order_id_lbl.Text = columns2[1];
state_lbl.Text = columns2[2];
cost_lbl.Text = columns2[3];
img_form_instance.ImageUrl = form_relPath;
img_timeschedule.ImageUrl = schedule_relPath;
img_invoice.ImageUrl = invoice_relPath;
notificatin_lbl.Text = columns2[7];