System.Drawing.Image图像 批量生成并显示在web页面上

来源:互联网 发布:win10没有windows聚焦 编辑:程序博客网 时间:2024/06/05 17:00

结合gridview显示出来。代码如下:

aspx文件中:

 <asp:GridView ID="GridView1" runat="server" OnDataBound="GridView1_DataBound" OnRowDataBound="GridView1_RowDataBound"
        AutoGenerateColumns="False" Width="100px">
        <RowStyle BackColor="White" HorizontalAlign="Center" BorderWidth="0px"  BorderColor="White"/>
    <PagerStyle   HorizontalAlign="Center" BorderWidth="0px"  BorderColor="White" />
    <SelectedRowStyle BackColor="White" Font-Bold="True" ForeColor="White" />
    <HeaderStyle  HorizontalAlign="Center"  BorderWidth="0px"  BorderColor="White"/>
    <AlternatingRowStyle BackColor="White"  BorderWidth="0px"  BorderColor="White" />  
    <FooterStyle  BorderWidth="0px"  BorderColor="White" HorizontalAlign="Center" />  
        <Columns>
            <asp:TemplateField HeaderText="請直接打印(ctrl+P)">
                <ItemTemplate>
                    <asp:Label ID="Label1" runat="server" Text='<%# Bind("JiZhong") %>'></asp:Label>-
                    <asp:Label ID="Label2" runat="server" Text='<%# Bind("MoNO") %>'></asp:Label>-
                    <asp:Label ID="Label3" runat="server" Text='<%# Bind("JianNO") %>'></asp:Label>
                    <br/>
                    <asp:Image ID="barcodeimg" runat="server" ToolTip='<%# Bind("ID") %>'/>
                </ItemTemplate>
            </asp:TemplateField>
        </Columns>
        <EmptyDataTemplate>
            無資料!
        </EmptyDataTemplate>
    </asp:GridView>


cs文件中:

protected void GridView1_DataBound(object sender, EventArgs e)

        {
            for (int i = 0; i < GridView1.Rows.Count; i++)
            {
                System.Web.UI.WebControls.Image barcodeimg = (System.Web.UI.WebControls.Image)GridView1.Rows[i].Cells[0].FindControl("barcodeimg");
                barcodeimg.ImageUrl = "~/code128.aspx?num=" + barcodeimg.ToolTip.ToString();
            }
        }