0

我有以下 aspx 和 cs

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="cardPrintingBarcode.aspx.cs" Inherits="Reports_cardPrintingBarcode" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
        <title>
            Impresión de Tarjeta
        </title>

        <style type="text/css">
            .style2
            {
                font-size: xx-small;
            }
        </style>
    </head>

    <body>
        <form id="form1" runat="server">
            <div id="Card">
                <table>
                    <tr>
                        <td width="85px" align="center" valign="bottom">
                            <image ID="imgBarcode" Width="85px" Height="20px" />
                            <br />

                            <label ID="lblCardcode" Font-Bold="True" Font-Names="Arial" Font-Size="5pt" >
                            </label>
                        </td>

                        <td width="30px" />

                        <td width="40px" align="center" valign="bottom">
                            <label ID="lblCN" Font-Bold="True" Font-Names="Arial" Font-Size="7pt">
                            </label>

                            <br />
                            <image ID="imgQR" Width="37px" Height="37px" />
                        </td>
                    </tr>
                </table>
            </div>
        </form>
    </body>
</html>



using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Collections.Generic;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using ClubCard.Core;

public partial class Reports_cardPrintingBarcode : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (ViewState["CHECKED_CARDS_ITEMS"] != null)
        {
            if (((List<int>)ViewState["CHECKED_CARDS_ITEMS"]).Count > 0)
            {
                LoadCards();
            }

            else
            {
                this.Response.Redirect("~/default.aspx");
                //GET ME OUT OF HERE
            }
        }
    }

    private void LoadCards()
    {
        List<int> lstIdCards = (List<int>)ViewState["CHECKED_CARDS_ITEMS"];

        foreach (int intIdCard in lstIdCards)
        {
            //Process Where I Want To Assign Data To 2 Labels and 2 images
            ClubCard.Core.Card card = new ClubCard.Core.Card(intIdCard);
            ClubCard.Core.Client client = new ClubCard.Core.Client(card.idClient);
            Byte[] bcQR = QR.GetQRByteArray(card.cardCode);
            string strBase64 = Convert.ToBase64String(bcQR, 0, bcQR.Length);

            //lblCN.Text = client.number;
            //lblCardCode.Text = card.number;
            //imgBarcode.ImageUrl = "SOME URL";
            //imgQR.ImageUrl = "SOME URL";

            //PROBABLY HERE'S WHERE I HAVE TO CREATE ALL WEBCONTROLS...
            //THEN WHEN THE FOREACH STARTS AGAIN, CREATE ANOTHER ONE...
        }
    }
}

这里的重点是创建在 aspx 中看到的表的次数与 (List)ViewState["CHECKED_CARDS_ITEMS"]).Count 一样多。

例如...如果 (List)ViewState["CHECKED_CARDS_ITEMS"]).Count = 5,那么我想查看表格及其所有内容 5 次(显然,每个都会不同,因为我分配的服务器端不同数据到每个,因此,使用 foreach)

如何克隆那些 WebControls?我听说我不能在这些控件上使用 runat="server" (但是我不确定在这个例子中是否可以工作),其他一些消息来源声称它应该在一个 div 内,并克隆 div。

4

1 回答 1

2

您可能需要一个 ListControl 例如<asp:DataList /><asp:GridView

创建您的卡片列表

List<ClubCard.Core.Card> cards = new List<ClubCard.Core.Card>();
//cards.Add(...some cards...);
//cards.Add(...some cards...);
//cards.Add(...some cards...);

将您的列表绑定到 ListControl

cardListControl.DataSource = cards;
cardListControl.DataBind();

用 DataList 实现它:

<asp:DataList runat="server" ID="cardListControl">
<ItemTemplate>
    <!-- Layout to display card here -->
    <img src='<%# Eval("CardImageUrl")>' />
    <span><%# Eval("CardName") %></span>
    <!-- other card information -->
</ItemTemplate>
</asp:DataList>

DataList 有一个RepeatDirection属性,可让您水平或垂直显示卡片

于 2013-04-23T15:52:01.950 回答