Last Updated: February 25, 2016
·
2.254K
· petermorlion

KnockoutJS and ASP.NET Repeater

The foreach binding in Knockout is a powerful and handy binding and can be used to create tables. But sometimes you're stuck with old-school ASP.NET Repeaters to create your tables (and a lot is done server-side). The good news is you can still use Knockout, just not the foreach binding.

In fact, it's quite simple. Just use the following syntax in the ItemTemplate of your Repeater:

<tr data-bind="with: myItems()[<%# Container.ItemIndex %>]"></tr>

You can find a full explanation on my blog and a working example on GitHub.

Have a fresh tip? Share with Coderwall community!

Post
Post a tip
Did you know?

JavaScript on a page runs with the privileges of that origin. One altered library, tag manager, or snippet can read inputs, change what people see, and call your APIs as the user.

Security insights from Cside