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...
        }
    }
}

ここでのポイントは、(List)ViewState["CHECKED_CARDS_ITEMS"]).Count の回数だけ aspx に表示されるテーブルを作成することです。

たとえば... if (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 に答える