谁能帮助我如何使用C#在ASP.net中创建一个分层的超网格网...我对这个很陌生...所以我需要一些基础知识和示例代码..你能帮我吗?
发布于 2009-03-01 15:40:00
使UltraWebGrid“分层”的一种方法是在数据集中建立数据关系,并将数据集绑定到UltraWebGrid。
例如,假设我们有一个博客,我们希望将博客文章显示为父级,然后将对每篇文章的任何评论显示为分层UltraWebGrid中的子级。父表名为"BlogArticle“,关键字为"BlogArticleID”,子表名为"BlogComment“,包含一个"BlogArticleID”列,作为"BlogArticle“的外键。
首先,我们将建立两个数据集,并使用您喜欢的任何机制来填充我们想要的数据。在本例中,我只是检索所有的博客文章和评论。然后,我们将“合并”将要成为子代的数据集到属于父代的数据集。最后,我们将在dataset中设置数据关系,并将dataset绑定到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查看我组装的示例。
我希望这对你有帮助,谢谢
发布于 2009-02-27 10:09:16
你要找的是this吗?
https://stackoverflow.com/questions/594160
复制相似问题