在每个Repeater ItemTemplate中生成条形码

问题描述 投票:-1回答:1

我计划在asp转发器中使用jquery条形码库生成条形码。

转发器工作良好,显示检索到的所有数据。

问题在于条形码生成。

请帮忙。

<script src="Scripts/jquery-3.1.1.min.js"></script>
<script src="Scripts/jquery-barcode.js"></script>
<script type="text/javascript">
    function GetBarcode(_refEnvoi) {
        $("#bcTarget").barcode(_refEnvoi, "code128", { barWidth: 2, 
     barHeight: 50, output: 'css' });
    };

</script>

<form id="form1" runat="server">
<asp:Repeater runat="server" ID="repAllEnvois" ClientIDMode="Static" 
 OnItemDataBound="repAllEnvois_ItemDataBound">
        <ItemTemplate>
 <asp:Label ID="txtrefEnvoi" runat="server" Text='<%# Eval("refEnvoi") %>' 
 />
<div id="bcTarget" runat="server" class="pull-right" style="height: 70px"> 
</div>
</ItemTemplate>
        <SeparatorTemplate>
            <h2 style="page-break-before: always;"></h2>
            <br />
        </SeparatorTemplate>

    </asp:Repeater>

 </form>

代码背后

    protected void repAllEnvois_ItemDataBound(object sender, RepeaterItemEventArgs e)
    {
        if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType == ListItemType.AlternatingItem)
        {
            RepeaterItem item = e.Item;

            string refBarcode = (item.FindControl("txtrefEnvoi") as Label).Text;

            ClientScript.RegisterClientScriptBlock( this.GetType(), "GetBarcode", "GetBarcode(+'refBarcode'+)", true);l;
        }
    }
javascript c# jquery asp.net repeater
1个回答
0
投票

试试这个

<img class="barcode" data-id='<%# Eval("refEnvoi") %>' />

在您希望条形码出现的转发器内部

at按钮使用此脚本生成条形码

<script>
$(function(){
    var $barcode = $(".barcode");
    $barcode.each(function () {
        var bc = $(this).data('id').toString();
        $(this).JsBarcode(bc, { "format": "code128", "backgroundColor": "#fff", "fontSize": 16, "height": 40, "width": 1, "displayValue": true }, function (valid) {

        });
    });
});
</script>

需要JSBarcode library

© www.soinside.com 2019 - 2024. All rights reserved.