Chartjs-How to add Canvas tag inside repeater

0👍

The first thing you need to to is make sure every canvas has a unique ID. You can do that by adding the ItemIndex to the id.

<canvas id="mychart_<%# Container.ItemIndex %>"></canvas>

After that you can use JavasScript to build the charts. There you use <%= Repeater1.Items.Count %> to get the total item count.

<script type="text/javascript">
    $(document).ready(function () {
        for (var i = 0; i < <%= Repeater1.Items.Count %>; i++) {
            buildCanvas("mychart_" + i);
        }
    });
</script>

Leave a comment