下面的<img src="./imagebase/1.jpg" alt="" />就可以显示出来,而Gridview中的图片就显示不出来,将ima改为img也不行,希望各位帮帮忙
本人很菜,希望各位回答是能说说具体应该怎样写,错在哪里
- HTML code
<%@ Page Title="Home Page" Language="C#" MasterPageFile="~/Site.master" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %><asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="HeadContent"></asp:Content><asp:Content ID="BodyContent" runat="server" ContentPlaceHolderID="MainContent"> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" onpageindexchanging="GridView1_PageIndexChanging" Width="624px"> <PagerSettings FirstPageText="第一页" LastPageText="最后页" NextPageText="下一页" Position="TopAndBottom" PreviousPageText="上一页" /> <Columns> <asp:TemplateField> <ItemTemplate> <ima alt="" src='〈%# DataBinder.Eval(Container, "DataItem.filePath", "{0}") %>'/> </ItemTemplate> </asp:TemplateField> </Columns> </asp:GridView> <img src="./imagebase/1.jpg" alt="" /></asp:Content>
- C# code
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using System.Web.UI.WebControls;using System.Data;using System.Net;using System.Text.RegularExpressions;public partial class _Default : System.Web.UI.Page{ protected void Page_Load(object sender, EventArgs e) { DataTable dt = new DataTable(); dt.Columns.Add("filePath"); DataRow dr = dt.NewRow(); dr["filePath"] = "./imagesbase/1.jpg"; dt.Rows.Add(dr); this.GridView1.DataSource = dt; this.GridView1.DataBind(); } protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e) { }}
网页运行是查看源代码,是
- HTML code
<div> <table cellspacing="0" rules="all" border="1" id="MainContent_GridView1" style="width:624px;border-collapse:collapse;"> <tr> <th scope="col"> </th> </tr><tr> <td> <ima alt="" src='〈%# DataBinder.Eval(Container, "DataItem.filePath", "{0}") %>'/> </td> </tr> </table></div> <img src="./imagebase/1.jpg" alt="" />
点击这里的<ima alt="" src='〈%# DataBinder.Eval(Container, "DataItem.filePath", "{0}") %>'/>可以看到以下源代码
- HTML code
<html> <head> <title>Bad Request</title> <style> body {font-family:"Verdana";font-weight:normal;font-size: 8pt;color:black;} p {font-family:"Verdana";font-weight:normal;color:black;margin-top: -5px} b {font-family:"Verdana";font-weight:bold;color:black;margin-top: -5px} h1 { font-family:"Verdana";font-weight:normal;font-size:18pt;color:red } h2 { font-family:"Verdana";font-weight:normal;font-size:14pt;color:maroon } pre {font-family:"Lucida Console";font-size: 8pt} .marker {font-weight: bold; color: black;text-decoration: none;} .version {color: gray;} .error {margin-bottom: 10px;} .expandable { text-decoration:underline; font-weight:bold; color:navy; cursor:hand; } </style> </head> <body bgcolor="white"> <span><h1>Server Error in '/WebSite2' Application.<hr width=100% size=1 color=silver></h1> <h2> <i>HTTP Error 400 - Bad Request.</i> </h2></span> <hr width=100% size=1 color=silver> <b>Version Information:</b> ASP.NET Development Server 10.0.0.0 </font> </body></html>