GridView绑定图片并分页_第1页
GridView绑定图片并分页_第2页
GridView绑定图片并分页_第3页
全文预览已结束

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

1、绑定数据源之后,编辑列-在可用字段中选择ImageField字段,点击添加按钮。在下方选定字段中选择刚才的ImageField字段,在右侧属性里边找到DataImageUrlField,选择相应的数据库字段就可以了。前台:<div style="width:713px;height:500px;"><br/> <asp:GridView ID="GridView1" runat="server" AllowPaging="True" OnPageIndexChanging="

2、Part_PageIndexChanging" CellPadding="4" PageSize="3" AutoGenerateColumns="False" Font-Size="9pt" Width="713px" HorizontalAlign="Center" BackColor="White" BorderColor="#3366CC" BorderStyle="None" BorderWidt

3、h="1px" OnRowDataBound="GridView1_RowDataBound" Height="234px"> <RowStyle ForeColor="#003399" BackColor="White" /> <Columns> <asp:BoundField DataField="computerID" HeaderText="电脑型号"/> <asp:BoundField DataFi

4、eld="computerName" HeaderText="电脑名" /> <asp:BoundField DataField="computerPrice" HeaderText="电脑报价" /> <asp:ImageField DataImageUrlField="computerUrl" ControlStyle-Width="180px" ControlStyle-Height="140px" HeaderText=&q

5、uot;电脑图片"><ControlStyle Height="140px" Width="180px"></ControlStyle> </asp:ImageField> <asp:BoundField DataField="computerText" HeaderText="简述" /> </Columns> <EmptyDataTemplate> 抱歉,您要查询的信息不存在! </EmptyDataTemplate&

6、gt; <FooterStyle BackColor="#99CCCC" ForeColor="#003399" /> <PagerStyle BorderColor="Blue" BackColor="#99CCCC" ForeColor="#003399" HorizontalAlign="Left" /> <SelectedRowStyle BackColor="#009999" Font-Bold="True

7、" ForeColor="#CCFF99" /> <HeaderStyle BackColor="#003399" Font-Bold="True" ForeColor="#CCCCFF" /> </asp:GridView></div>后台:using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.UI;using Syste

8、m.Web.UI.WebControls;using System.Data;using System.Data.SqlClient;using System.Configuration;public partial class GridView : System.Web.UI.Page protected void Page_Load(object sender, EventArgs e) if (!IsPostBack) Bind(); protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)

9、foreach (TableCell tc in e.Row.Cells) tc.Attributes"style" = "border-color:Black" if (e.Row.RowIndex != -1) int id = GridView1.PageIndex * GridView1.PageSize + e.Row.RowIndex + 1; e.Row.Cells0.Text = id.ToString(); protected void Part_PageIndexChanging(object sender, GridViewPage

10、EventArgs e) GridView1.PageIndex = e.NewPageIndex; Bind(); public void Bind() try SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings"connstr".ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.CommandText = "select * from computerImage" cmd.Connection = cn; cn.Open(); SqlDataAdapter da = new SqlDataAdapter(); da.SelectCommand = cmd; DataSet ds = new DataSe

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论