Dynamic column with value appearing wrong in Webgrid

Asked

Viewed 101 times

0

I have a problem when creating a table with dynamic columns. I add the columns in a loop this way:

for (int i = 0; i < attrIds.Count; i++)
        {
            resource_attr attr = resourceAttrRepository.Find(attrIds[i]);

            int local = i;
            columns.Add(new WebGridColumn()
            {
                ColumnName = attr.code,
                Header = attr.resource_attr_name,
                Style = "column-attr",
                CanSort = true,
                Format = (item) => (((List<string>)item.attrValues).Count < local) ? @item.attrValues[local] : "out"
            });
        }

The header column is correct, but the value is always appearing "out".

I am using ASP.Net MVC 4 and the Webgrid component.

1 answer

1

The Value always appears OUT because it falls in the if ternary Else

Format = (item) => (((List<string>)item.attrValues).Count < local) ? @item.attrValues[local] : "SEMPRE ESTÁ CAINDO AQUI."
  • yes, but because it always falls on Else? debugging I see that the local variable is always greater than the amount of objects within the item list.attrValues

Browser other questions tagged

You are not signed in. Login or sign up in order to post.