• 在GridView控件中显示图像


    放一个 GridView 放上一个ImageField 来显示图像
    前台代码

    <table border="0" cellpadding="0" cellspacing="0" style=" 133px; height: 101px">
                <tr>
                    <td style=" 100px">
                        <asp:GridView ID="GridView1" runat="server" CellPadding="4" ForeColor="#333333" GridLines="None" Height="215px" Width="297px" OnPageIndexChanged="GridView1_PageIndexChanged" OnPageIndexChanging="GridView1_PageIndexChanging" OnSelectedIndexChanged="GridView1_SelectedIndexChanged">
                            <FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <Columns>
                                <asp:ImageField AlternateText="员工头像" HeaderText="员工头像" DataImageUrlField="photo">  // 绑定数据
                                </asp:ImageField>
                            </Columns>
                            <RowStyle BackColor="#EFF3FB" />
                            <EditRowStyle BackColor="#2461BF" />
                            <SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" />
                            <PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
                            <HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
                            <AlternatingRowStyle BackColor="White" />
                        </asp:GridView>
                    </td>
                </tr>
            </table>

    protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection();
            string sql = "select * from tb_user";
            SqlDataAdapter sda = new SqlDataAdapter(sql, con);
            DataSet ds = new DataSet();
            sda.Fill(ds,"tb_user");
            DataRowView drv = ds.Tables["tb_user"].DefaultView[0];
            this.GridView1.DataSource = drv;
            this.GridView1.DataBind();
            this.GridView1.Columns[0].HeaderImageUrl =Convert.ToString(drv["photo"]);
    //此处用到了HeaderImageUrl 来从数据库里得到图像的路径来显示图片


        }
    protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            this.GridView1.PageIndex = e.NewPageIndex;
            this.GridView1.DataBind();
        }

  • 相关阅读:
    ASP.NET通用权限管理系统(FrameWork) 1.0.0 Release 发布
    ASP.NET通用权限管理系统(FrameWork) 1.0.3 Release
    ASP.NET通用权限管理系统(FrameWork) 之用户在线列表 泛型缓存 [原创]
    DDBuildToolsRelease1.0
    FineMessBox弹出窗口js (修改版,增加对Firefox支持)
    [开源]ASP.NET通用权限管理系统(FrameWork) 1.0.2 Release
    [开源]ASP.NET通用权限管理系统(FrameWork) 1.0.1 Release
    如何在CodePlex 创建开源项目
    今天上班遇到好人了
    ASP.NET通用权限管理系统(FrameWork) 在线演示地址
  • 原文地址:https://www.cnblogs.com/ivy/p/1216108.html
Copyright © 2020-2023  润新知