Reputation:
Can anyone help me how to create a hierarchical Ultrawebgrid in ASP.net using C#... I'm very new to this... So i need some basics and sample codes .. Can u help me ?
Upvotes: 2
Views: 2350
Reputation: 423
One way to make an UltraWebGrid "Hierarchical" is to establish a data relation in a dataset and bind the dataset to the UltraWebGrid.
As an example, let's say we have a Blog and we want to show the Blog Articles as the parent and then any comments made to each article as children in a Hierarchical UltraWebGrid. The parent table is named "BlogArticle" and is keyed by "BlogArticleID" and the child table is named "BlogComment" and contains a "BlogArticleID" column as a foreign key to "BlogArticle".
First we would establish 2 datasets and fill them using whatever mechanism you prefer with the data we want. In this case I am simply retrieving all the Blog Articles and all the Comments. Then we would "merge" the dataset that is to be the child into the dataset that is to the parent. Finally, we would set our data relationship in the dataset and bind the dataset to the UltraWebGrid.
An example of the code for this is as follows...
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();
The UltraWebGrid will automatically handle creating the Hierarchical grid based on the Data Relationship that is established in the dataset. To see this code populate an UltraWebGrid you can go here to view an example that I put together.
I hope this helps, Thanks
Upvotes: 3