任何人都可以帮助我如何使用 C# 在 ASP.net 中创建分层 Ultrawebgrid...我对此很陌生...所以我需要一些基础知识和示例代码..你可以帮助我吗?
最佳答案
使 UltraWebGrid“分层”的一种方法是在数据集中建立数据关系并将数据集绑定(bind)到 UltraWebGrid。
举个例子,假设我们有一个博客,我们希望将博客文章显示为父级,然后将每篇文章的任何评论显示为分层 UltraWebGrid 中的子级。父表名为“BlogArticle”,并以“BlogArticleID”为键,子表名为“BlogComment”,并包含“BlogArticleID”列作为“BlogArticle”的外键。
首先,我们将建立 2 个数据集,并使用您喜欢的任何机制填充我们想要的数据。在本例中,我只是检索所有博客文章和所有评论。然后我们将作为子项的数据集“合并”到作为父项的数据集。最后,我们将在数据集中设置数据关系并将数据集绑定(bind)到 UltraWebGrid。
代码示例如下...
DataSet dsBlogArticle = new DataSet();
DataSet dsBlogComment = new DataSet();
//
// Fill each dataset appropriately.
//
// Set Table Names. This is needed for the merge operation.
dsBlogArticle.Tables[0].TableName = "BlogArticle";
dsBlogComment.Tables[0].TableName = "BlogComment";
//
// Merge the Blog Comment dataset into the Blog Article dataset
// to create a single dataset object with two tables.
dsBlogArticle.Merge(dsBlogComment);
//
// Define Hierarchical relationships in the Dataset.
DataRelation dr = new DataRelation(
"BlogArticleToComments",
dsBlogArticle.Tables["BlogArticle"].Columns["BlogArticleID"],
dsBlogArticle.Tables["BlogComment"].Columns["BlogArticleID"],
false);
dsBlogArticle.Relations.Add(dr);
//
// Bind the dataset to the grid.
this.grdBlogArticle.DataSource = dsBlogArticle;
this.grdBlogArticle.DataBind();
UltraWebGrid 将根据数据集中建立的数据关系自动处理分层网格的创建。要查看此代码填充 UltraWebGrid,您可以 go here查看我整理的示例。
希望这对您有所帮助,谢谢
关于asp.net - 分层网格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/594160/