Hi!
I have a question: how can I bind a list of custom objects to a radgridview, where each custom object itself contains a list of custom objects.
Here is an example to get a clearer:
===========================
Custom Objects:
public class ArticleData()
{
public string MonthName { get; set; }
public decimal MonthValue { get; set; }
}
public class Article()
{
public string ArticleNo { get; set; )
public string ArticleName { get; set; )
public List<ArticleData> ArticleDetails();
public Article()
{
ArticleDetails = new List<ArticleData>();
}
}
Filling with test data:
List<Article> ArticleList = new List<Article>();
Article a = new Article();
a.ArticleNo = "1000";
a.ArticleName = "Testarticle 1000";
a.ArticleDetails.add(new ArticleData { MonthName = "January", MonatValue = 10 });
a.ArticleDetails.add(new ArticleData { MonthName = "February", MonatValue = 5 });
...
ArticleList.add(a);
Article b = new Article();
b.ArticleNo = "2000";
b.ArticleName = "Testarticle 2000";
b.ArticleDetails.add(new ArticleData { MonthName = "January", MonatValue = 6 });
b.ArticleDetails.add(new ArticleData { MonthName = "February", MonatValue = 3 });
...
ArticleList.add(b);
and so on ...
DataBinding to Grid:
Imagine, I have a grid, with 14 columns: the first two columns should represent ArticleNo and ArticleName. The other columns should represent 12 months of a year with each MonthValue.
GridViewTextColumn colArticleNo = new GridViewTextBoxColumn();
colArticleNo.FieldName = "ArticleNo";
radgridview1.columns.add(colArticleNo);
GridViewTextColumn colArticleName = new GridViewTextBoxColumn();
colArticleName.FieldName = "ArticleName";
radgridview1.columns.add(colArticleName);
GridViewDecimalColumn colJanuary = new GridViewDecimalColumn();
colJanuary.FieldName = "Article.ArticleDetails.MonthValue";
GridViewDecimalColumn colFebruary = new GridViewDecimalColumn();
colFebruary.FieldName = "Article.ArticleDetails.MonthValue";
radgridview1.DataSource = ArticleList;
How can I achieve, that for the January column, the ArticleDetails[0].MonthValue is bound, for the February column ArticleDetails[1].MonthValue ist bound and so on??
Kind regards
Michael
I have a question: how can I bind a list of custom objects to a radgridview, where each custom object itself contains a list of custom objects.
Here is an example to get a clearer:
===========================
Custom Objects:
public class ArticleData()
{
public string MonthName { get; set; }
public decimal MonthValue { get; set; }
}
public class Article()
{
public string ArticleNo { get; set; )
public string ArticleName { get; set; )
public List<ArticleData> ArticleDetails();
public Article()
{
ArticleDetails = new List<ArticleData>();
}
}
Filling with test data:
List<Article> ArticleList = new List<Article>();
Article a = new Article();
a.ArticleNo = "1000";
a.ArticleName = "Testarticle 1000";
a.ArticleDetails.add(new ArticleData { MonthName = "January", MonatValue = 10 });
a.ArticleDetails.add(new ArticleData { MonthName = "February", MonatValue = 5 });
...
ArticleList.add(a);
Article b = new Article();
b.ArticleNo = "2000";
b.ArticleName = "Testarticle 2000";
b.ArticleDetails.add(new ArticleData { MonthName = "January", MonatValue = 6 });
b.ArticleDetails.add(new ArticleData { MonthName = "February", MonatValue = 3 });
...
ArticleList.add(b);
and so on ...
DataBinding to Grid:
Imagine, I have a grid, with 14 columns: the first two columns should represent ArticleNo and ArticleName. The other columns should represent 12 months of a year with each MonthValue.
GridViewTextColumn colArticleNo = new GridViewTextBoxColumn();
colArticleNo.FieldName = "ArticleNo";
radgridview1.columns.add(colArticleNo);
GridViewTextColumn colArticleName = new GridViewTextBoxColumn();
colArticleName.FieldName = "ArticleName";
radgridview1.columns.add(colArticleName);
GridViewDecimalColumn colJanuary = new GridViewDecimalColumn();
colJanuary.FieldName = "Article.ArticleDetails.MonthValue";
GridViewDecimalColumn colFebruary = new GridViewDecimalColumn();
colFebruary.FieldName = "Article.ArticleDetails.MonthValue";
radgridview1.DataSource = ArticleList;
How can I achieve, that for the January column, the ArticleDetails[0].MonthValue is bound, for the February column ArticleDetails[1].MonthValue ist bound and so on??
Kind regards
Michael