asp.net(c#) 求gridview显示图片方法!!!

最好有代码,灰常感谢!... 最好有代码,灰常感谢! 展开
 我来答
匿名用户
2013-07-21
展开全部
你把图片全部存储到某个路径(文件夹)中,然后把这个文件夹放到项目中,数据表中包含一个图片的相对路径即可(点击, http://www.microsofttranslator.com/bv.aspx?ref=Internal&from=&to=zh-chs&a= http://msdn.microsoft.com/en-us/library/aa479350.aspx,查看)。 这是我的一个例子:DataTable GetData()
{
// This method creates a DataTable with four rows. Each row has the
// following schema:
// PictureID int
// PictureURL string
// Title string
// DateAdded datetime
DataTable dt = new DataTable();
// define the table's schema
dt.Columns.Add(new DataColumn("PictureID", typeof(int)));
dt.Columns.Add(new DataColumn("PictureURL", typeof(string)));
dt.Columns.Add(new DataColumn("Title", typeof(string)));
dt.Columns.Add(new DataColumn("DateAdded", typeof(DateTime)));
// Create the four records
DataRow dr = dt.NewRow();
dr["PictureID"] = 1;
dr["PictureURL"] = ResolveUrl("~/DisplayingImages/Images/Blue hills.jpg");
dr["Title"] = "Blue Hills";
dr["DateAdded"] = new DateTime(2005, 1, 15);
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["PictureID"] = 2;
dr["PictureURL"] = ResolveUrl("~/DisplayingImages/Images/Sunset.jpg");
dr["Title"] = "Sunset";
dr["DateAdded"] = new DateTime(2005, 1, 21);
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["PictureID"] = 3;
dr["PictureURL"] =
ResolveUrl("~/DisplayingImages/Images/Water lilies.jpg");
dr["Title"] = "Water Lilies";
dr["DateAdded"] = new DateTime(2005, 2, 1);
dt.Rows.Add(dr);
dr = dt.NewRow();
dr["PictureID"] = 4;
dr["PictureURL"] = ResolveUrl("~/DisplayingImages/Images/Winter.jpg");
dr["Title"] = "Winter";
dr["DateAdded"] = new DateTime(2005, 2, 18);
dt.Rows.Add(dr);
return dt;
} void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
} Copy <asp:GridView ID="GridView1" Runat="server" DataSource='<%# GetData() %>' AutoGenerateColumns="False" BorderWidth="1px" BackColor="White" CellPadding="3" BorderStyle="None" BorderColor="#CCCCCC" Font-Names="Arial"> <FooterStyle ForeColor="#000066" BackColor="White"></FooterStyle> <PagerStyle ForeColor="#000066" HorizontalAlign="Left" BackColor="White"></PagerStyle> <HeaderStyle ForeColor="White" Font-Bold="True" BackColor="#006699"></HeaderStyle> <Columns> <asp:BoundField HeaderText="Picutre ID" DataField="PictureID"> <ItemStyle HorizontalAlign="Center" VerticalAlign="Middle"></ItemStyle> </asp:BoundField> <asp:BoundField HeaderText="Title" DataField="Title"></asp:BoundField> <asp:BoundField HeaderText="Date Added" DataField="DateAdded" DataFormatString="{0:d}"> <ItemStyle HorizontalAlign="Center"></ItemStyle> </asp:BoundField> <asp:ImageField DataImageUrlField="PictureURL"></asp:ImageField> </Columns> <SelectedRowStyle ForeColor="White" Font-Bold="True" BackColor="#669999"></SelectedRowStyle> <RowStyle ForeColor="#000066"></RowStyle> </asp:GridView>
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式