Hi there everyone........Im trying to create a grid with dynamic hierarchy drill down levels in code behind....this is my code
How can i get the Parent datakey to be able to insert that parameter within my dynamically generated sqldatasource.....Is it possible to have this done using radgrid control?? I know i can use the Tree View control but I the requirements fit the rad grid one.
Thks in advance
SqlConnection cn =
new
SqlConnection(connStr);
SqlDataAdapter da =
new
SqlDataAdapter(
"SELECT MAX(node) AS node FROM tabs"
, cn);
DataTable dt =
new
DataTable();
if
(cn.State == ConnectionState.Closed)
{
cn.Open();
}
try
{
da.Fill(dt);
}
catch
{ }
if
(dt !=
null
&& dt.Rows.Count > 0)
{
Int32 node = Convert.ToInt32(dt.Rows[0][
"node"
].ToString());
RadGrid RadGrid1 =
new
RadGrid();
SqlDataSource sdsMaster =
new
SqlDataSource(connStr,
"SELECT * FROM tabs WHERE active=1 AND idParentNode = '0' ORDER BY displayOrder"
);
sdsMaster.ID =
"sqlDataSourceMaster"
;
phGridContainer.Controls.Add(sdsMaster);
RadGrid1.ID =
"RadGrid1"
;
RadGrid1.DataSourceID =
"SqlDataSourceMaster"
;
RadGrid1.MasterTableView.DataKeyNames =
new
string
[] {
"id"
};
RadGrid1.Width = Unit.Percentage(98);
RadGrid1.PageSize = 3;
RadGrid1.AllowPaging =
true
;
RadGrid1.AllowSorting =
true
;
RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
RadGrid1.AutoGenerateColumns =
false
;
RadGrid1.ShowStatusBar =
true
;
RadGrid1.MasterTableView.PageSize = 10;
//Add columns
GridBoundColumn boundColumn;
boundColumn =
new
GridBoundColumn();
boundColumn.DataField =
"id"
;
boundColumn.HeaderText =
"ID"
;
RadGrid1.MasterTableView.Columns.Add(boundColumn);
boundColumn =
new
GridBoundColumn();
boundColumn.DataField =
"label"
;
boundColumn.HeaderText =
"Tab"
;
RadGrid1.MasterTableView.Columns.Add(boundColumn);
if
(node > 0)
{
for
(
int
i = 1; i <= node; i++)
{
SqlDataSource sds =
new
SqlDataSource(connStr,
"SELECT * FROM Tabs WHERE active=1 AND idParentNode = @id ORDER BY displayOrder"
);
/*THIS IS THE PART IM HAVING ISSUES*/
sds.SelectParameters.Add(
"id"
, RadGrid1.MasterTableView.DataKeyValues[0].ToString());
sds.ID =
"sqlDataSource"
+ i.ToString();
phGridContainer.Controls.Add(sds);
GridTableView tableViewDetail =
new
GridTableView(RadGrid1);
tableViewDetail.DataSourceID =
"sqlDataSource"
+ i.ToString();
tableViewDetail.Width = Unit.Percentage(100);
tableViewDetail.DataKeyNames =
new
string
[] {
"id"
};
GridRelationFields relationFields =
new
GridRelationFields();
relationFields.MasterKeyField =
"id"
;
relationFields.DetailKeyField =
"idParentNode"
;
tableViewDetail.ParentTableRelation.Add(relationFields);
RadGrid1.MasterTableView.DetailTables.Add(tableViewDetail);
//Add columns
boundColumn =
new
GridBoundColumn();
boundColumn.DataField =
"id"
;
boundColumn.HeaderText =
"ID"
;
tableViewDetail.Columns.Add(boundColumn);
boundColumn =
new
GridBoundColumn();
boundColumn.DataField =
"label"
;
boundColumn.HeaderText =
"Tab"
;
tableViewDetail.Columns.Add(boundColumn);
}
}
phGridContainer.Controls.Add(RadGrid1);
}
cn.Close();
How can i get the Parent datakey to be able to insert that parameter within my dynamically generated sqldatasource.....Is it possible to have this done using radgrid control?? I know i can use the Tree View control but I the requirements fit the rad grid one.
Thks in advance