i am using the code given below to add a grid template .in this controls are
dgrdsubcategory -> RAD GRID
category is the table from database it returns
Please Reply at earliest
dgrdsubcategory -> RAD GRID
category is the table from database it returns
Please Reply at earliest
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
//i get values in the template variable
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
///But though i have done this i dont get the corresponding result.
//It shows a "+" sign but nothing comes under it when clicked on "+"
public static SqlDataAdapter FillDataset(string strTableName) {
ds = new SqlDataAdapter();
sda=new SqlDataAdapter();
conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conString"];
string strCmd = "select * from " + strTableName;
sqlcommand sqlCmd = new SqlCommand(strCmd, conn);
sda = new SqlDataAdapter(sqlCmd);
//sda.Fill(ds);
//dgrdv.DataSource = ds.Tables[0];
}
catch (Exception excep)
{
MessageBox.Show("" + excep.Message + " Stack Trace:" + excep.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return sda;
}
lic static SqlDataAdapter FillDataset(string strTableName)
{
SqlDataAdapter ds = new SqlDataAdapter();
SqlDataAdapter sda=new SqlDataAdapter();
try
{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = ConfigurationSettings.AppSettings["conString"];
string strCmd = "select * from " + strTableName;
SqlCommand sqlCmd = new SqlCommand(strCmd, conn);
sda = new SqlDataAdapter(sqlCmd);
//sda.Fill(ds);
//dgrdv.DataSource = ds.Tables[0];
}
catch (Exception excep)
{
MessageBox.Show("" + excep.Message + " Stack Trace:" + excep.StackTrace, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
return sda;
}
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
int count = dsCatid.Tables[0].Rows.Count;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
int count = dsCatid.Tables[0].Rows.Count;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
int count = dsCatid.Tables[0].Rows.Count;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
int count = dsCatid.Tables[0].Rows.Count;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
int count = dsCatid.Tables[0].Rows.Count;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
dgrdSubCategory.AutoGenerateHierarchy = true;
SqlDataAdapter sdaCatid = null;
DataSet dsCatid = new DataSet();
DataSet dsGrid = DBFunctions.FillRadDataGirdReturnDS("category where parentcatid IN (select catid from category where catname='" + TV1.SelectedNode.Text + "')", dgrdSubCategory);
for (int i = 0; i < dsGrid.Tables[0].Rows.Count; i++)
{
DataRow drow = dsGrid.Tables[0].Rows[i];
sdaCatid = FillDataset("category where parentcatid='" + drow["catid"] + "'");
sdaCatid.Fill(dsCatid);
}
int count = dsCatid.Tables[0].Rows.Count;
GridViewTemplate template = new GridViewTemplate();
template.DataSource = dsCatid.Tables[0];
dgrdSubCategory.MasterGridViewTemplate.ChildGridViewTemplates.Add(template);
GridViewRelation relation = new GridViewRelation(dgrdSubCategory.MasterTemplate);
relation.ChildTemplate = template;
relation.RelationName = "SubCategory";
relation.ParentColumnNames.Add("catid");
relation.ChildColumnNames.Add("catid");
dgrdSubCategory.Relations.Add(relation);
radGrid1.DataSource = template;
11 Answers, 1 is accepted
0

Richard Slade
Top achievements
Rank 2
answered on 18 Nov 2010, 02:12 PM
Hello,
At first look, the problem appears to be that you are assigning the template as the datasource
You are doing everything correctly from what I see, but you need to set a valid datasource for both the child template and the RadGridView.
Let me know if this helps or if you need more assistance.
Richard
At first look, the problem appears to be that you are assigning the template as the datasource
radGrid1.DataSource = template;
You are doing everything correctly from what I see, but you need to set a valid datasource for both the child template and the RadGridView.
Let me know if this helps or if you need more assistance.
Richard
0

Sagar
Top achievements
Rank 1
answered on 18 Nov 2010, 02:24 PM
Hi Richard,
Thanks for replying
.Actually you r correct. But the line "radGrid1.DataSource = template;" was used for testing that the template is getting populated or not(Template gets populated) , i removed that line, but also i cant see the expanded grid. Do i have to turn some static properties on/off....
Thanks & Regards
Thanks for replying
.Actually you r correct. But the line "radGrid1.DataSource = template;" was used for testing that the template is getting populated or not(Template gets populated) , i removed that line, but also i cant see the expanded grid. Do i have to turn some static properties on/off....
Thanks & Regards
0

Richard Slade
Top achievements
Rank 2
answered on 18 Nov 2010, 02:32 PM
Hello Sagar,
The hierarchy grid is made up of a MasterTemplate (the main one of the RadGridView) and a child template in its most simple incarnation.
The relation (as you have in your code) specifies the relation of the columns.
The additional template that you are adding should have a datasource as well.
You also don't need the line
If once you have set your datasources correctly and removed this line it is still not working, please post me a sample where this can be replicated and I will alter it for you.
Thanks
Richard
The hierarchy grid is made up of a MasterTemplate (the main one of the RadGridView) and a child template in its most simple incarnation.
The relation (as you have in your code) specifies the relation of the columns.
The additional template that you are adding should have a datasource as well.
You also don't need the line
dgrdSubCategory.AutoGenerateHierarchy =
true
;
If once you have set your datasources correctly and removed this line it is still not working, please post me a sample where this can be replicated and I will alter it for you.
Thanks
Richard
0

Sagar
Top achievements
Rank 1
answered on 19 Nov 2010, 06:09 AM
Hey thanks Richard, I found where the problem is, it was in the relation.
Any ways Thanks a lot....
Any ways Thanks a lot....
0

Richard Slade
Top achievements
Rank 2
answered on 19 Nov 2010, 08:32 AM
Glad you got thst sorted.
Richard
Richard
0

Sagar
Top achievements
Rank 1
answered on 19 Nov 2010, 01:38 PM
Hi , Richard , i have one more problem , now that i have a Parent Grid and a Child Grid, and i want to have the values from the cells of Child Grid on mouse click . So that i can show that value, But i am not able to get it. I have attached the PIC of my datagrid, i want the value of Kroner.Please Help..
I hope you get the problem.
I hope you get the problem.
0

Richard Slade
Top achievements
Rank 2
answered on 19 Nov 2010, 01:54 PM
hello,
You can get the values from any of teh selected rows / cells at any time using SelectedRows / SelectedCells. The example below shows
showing in a messagebox the value from the first selected row, and first selected cell. This will work for both Parent and Child grids.
Is this what you needed?
hope that helps
Richard
You can get the values from any of teh selected rows / cells at any time using SelectedRows / SelectedCells. The example below shows
showing in a messagebox the value from the first selected row, and first selected cell. This will work for both Parent and Child grids.
Is this what you needed?
Private
Sub
RadGridView1_SelectionChanged(
ByVal
sender
As
System.
Object
, _
ByVal
e
As
System.EventArgs)
Handles
RadGridView1.SelectionChanged
If
Me
.RadGridView1.SelectedRows.Count > 0
Then
If
Me
.RadGridView1.SelectedRows(0).Cells(0).Value IsNot
Nothing
Then
MessageBox.Show(
Me
.RadGridView1.SelectedRows(0).Cells(0).Value.ToString())
End
If
End
If
End
Sub
hope that helps
Richard
0

Sagar
Top achievements
Rank 1
answered on 19 Nov 2010, 02:25 PM
Hi, Richard.
It is not working for me, ok please tell me how can I identify which is the grid (parent or child) in the event of radgrid1_cellclick(). Or do i have to check with other event..
Thanks in advance
It is not working for me, ok please tell me how can I identify which is the grid (parent or child) in the event of radgrid1_cellclick(). Or do i have to check with other event..
Thanks in advance
0
Accepted

Richard Slade
Top achievements
Rank 2
answered on 19 Nov 2010, 02:28 PM
Hello,
You can see which hierarchy level the current row is in when you click on the cell in this way
hope that helps, but let me know if you need more information
Richard
You can see which hierarchy level the current row is in when you click on the cell in this way
Private
Sub
RadGridView1_CellClick(
ByVal
sender
As
System.
Object
,
ByVal
e
As
Telerik.WinControls.UI.GridViewCellEventArgs)
Handles
RadGridView1.CellClick
MessageBox.Show(e.Row.HierarchyLevel.ToString())
' Will show 1 for top level
' Will show 2 for child level
End
Sub
hope that helps, but let me know if you need more information
Richard
0

Sagar
Top achievements
Rank 1
answered on 19 Nov 2010, 02:47 PM
Hi , Richard..
Thanks a Lot again....
Thanks a Lot again....
0

Richard Slade
Top achievements
Rank 2
answered on 19 Nov 2010, 02:48 PM
No problem. Glad that worked for you.
Richard
Richard