This is a migrated thread and some comments may be shown as answers.

[Solved] ASP.NET MVC3 dynamically number of columns

0 Answers 15 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Holger Matthias
Top achievements
Rank 1
Holger Matthias asked on 23 Oct 2012, 02:34 PM
Hi there,
we are developing an asp.net mvc3 web application using the Telerik MVC extension framework. Now I need to build a grid with fixed columns and an unkown number of columns in compile time.

Im using currently following Code in thew view to build the grid:
@(Html.Telerik().Grid<ViewArticleLevelPricePriceWindow>()
    .Name("PriceWindowGrid")
    .BindTo(this.Model.ArticleLevelPrices)
    .Columns(c => {
        c.Template(@<text><input type="radio" name="row" /></text>);
        c.Bound(t => t.PriceLevel);
        c.Bound(t => t.SalesPrice);
        c.Bound(t => t.PriceUnit);
 
        for (int i = 0; i < this.Model.ArticleLevelPrices.Count; ++i) { //loop over rows
            int columnCounter = 0;
            IDictionary<decimal, decimal> values = this.Model.ArticleLevelPrices[i].DiscountPercentBasicComissionPercentPair;
            IList<decimal> keys = values.Keys.ToList();
            decimal key, value;
 
            for (int j = 0; j < keys.Count; ++j) {
                key = keys[j];
                value = values[key];
 
                c.Template(t => key).HeaderTemplate(@<text><input type="radio" id="discount_{@columnCounter}" name="discount" /> @value</text>);
            }
 
            c.Template(t => string.Empty).HeaderTemplate(
            @<text><input type="radio" id="manualDiscount" name="discount" />
@this.Html.Telerik().NumericTextBox().Name("manualDiscountValue").DecimalDigits(0).MinValue(0).MaxValue(100).Value(0).Spinners(false).EmptyMessage(string.Empty).HtmlAttributes(new {
    style = "width:50px;"
}); </text>);
 
            c.Template(t => string.Empty).HeaderTemplate(@<text>Netto-VK</text>);
            if (!user.Role.SalesForce) {
                c.Template(t => string.Empty).HeaderTemplate(@<text>DB %</text>);
            }
        }
    })
)


And the result is that all columns showing the same key/value (key and value of the last loop). While debugging I saw, that the Data from the ViewModel are the expected values.

I'm thankful for any help!

Thank you :-)
Tags
Grid
Asked by
Holger Matthias
Top achievements
Rank 1
Share this question
or