Hello,
I really need to be able to programmatically create, and populate a hierarchical radgrid.
right now I am just working on two levels (master, one detail) and am trying to setup the load-on-demand functionality. I am getting the master to load, but when i try and expand a row, it just sits forever (with the statusbar doing something).
The query it is running for a row shouldn't take much longer than a second... here is the code I am working with:
Please, any help is appreciated! Getting past this road block is crucial!
I really need to be able to programmatically create, and populate a hierarchical radgrid.
right now I am just working on two levels (master, one detail) and am trying to setup the load-on-demand functionality. I am getting the master to load, but when i try and expand a row, it just sits forever (with the statusbar doing something).
The query it is running for a row shouldn't take much longer than a second... here is the code I am working with:
protected
void
Page_Load(
object
sender, EventArgs e)
{
_Grid.DetailTableDataBind +=
new
GridDetailTableDataBindEventHandler(_Grid_DetailTableDataBind);
_Grid.NeedDataSource +=
new
GridNeedDataSourceEventHandler(_Grid_NeedDataSource);
LoadGrid();
}
void
_Grid_NeedDataSource(
object
sender, GridNeedDataSourceEventArgs e)
{
if
(!e.IsFromDetailTable)
{
_Grid.DataSource = GetDataTable(
"county:zavala"
);
}
}
void
_Grid_DetailTableDataBind(
object
sender, GridDetailTableDataBindEventArgs e)
{
GridDataItem dataItem = (GridDataItem)e.DetailTableView.ParentItem;
switch
(e.DetailTableView.Name)
{
case
"PARENT"
:
{
//string ID = dataItem.GetDataKeyValue("ID").ToString();
e.DetailTableView.DataSource = GetDataTable(
"county:zavala"
);
break
;
}
case
"CHILD"
:
{
string
cscpID = dataItem.GetDataKeyValue(
"cscpID"
).ToString();
e.DetailTableView.DataSource = GetDataTable(
"cscpID:"
+ cscpID +
" view:WP"
);
break
;
}
}
}
private
SqlCommand QueryCommand(
string
Query)
{
SqlConnection conn =
new
SqlConnection(GetConnectionString(
"connTGS_"
));
SqlCommand cmd =
new
SqlCommand(
"tgs_.pd.NewQuery"
, conn);
cmd.CommandType = CommandType.StoredProcedure;
SqlParameter qry = cmd.Parameters.Add(
"@Query"
, SqlDbType.NVarChar, 2000);
qry.Value = Query;
SqlParameter iserror = cmd.Parameters.Add(
"@iserror"
, SqlDbType.Bit, 1);
iserror.Value =
false
;
return
cmd;
}
private
DataTable GetDataTable(
string
query)
{
SqlCommand cmd = QueryCommand(query);
SqlDataAdapter dA =
new
SqlDataAdapter(cmd);
DataTable dT =
new
DataTable();
dA.Fill(dT);
return
dT;
}
private
void
LoadGrid()
{
if
(!Page.IsPostBack)
{
_Grid.PageSize = 20;
_Grid.AllowPaging =
true
;
_Grid.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;
_Grid.AutoGenerateColumns =
false
;
_Grid.ShowStatusBar =
true
;
_Grid.ClientSettings.AllowColumnsReorder =
true
;
_Grid.ClientSettings.AllowDragToGroup =
true
;
_Grid.ClientSettings.AllowColumnHide =
true
;
InitRootBand(
ref
_Grid);
InitChildBand(
ref
_Grid);
}
_radAjaxMan.AjaxSettings.AddAjaxSetting(_Grid, _Grid);
}
private
void
InitRootBand(
ref
RadGrid grid)
{
//grid.DataMember = "PARENT";
grid.MasterTableView.DataKeyNames =
new
string
[] {
"id"
};
grid.Columns.Add(newColumn(
"id"
,
"ID"
,
"id"
,
null
,
false
));
grid.Columns.Add(newColumn(
"cid"
,
"cID"
,
"p_cID"
,
null
,
false
));
grid.Columns.Add(newColumn(
"opid"
,
"opID"
,
"p_opID"
,
null
,
false
));
grid.Columns.Add(newColumn(
"CompanyName"
,
"Company Name"
,
"p_CompanyName"
,
null
,
false
));
}
private
void
InitChildBand(
ref
RadGrid grid)
{
GridTableView tableWP =
new
GridTableView(grid);
grid.MasterTableView.DetailTables.Add(tableWP);
//tableWP.DataMember = "CHILD";
tableWP.Name =
"CHILD"
;
tableWP.DataKeyNames =
new
string
[] {
"cscpID"
};
tableWP.Columns.Add(newColumn(
"ID"
,
"ID"
,
"ID"
,
null
,
false
));
tableWP.Columns.Add(newColumn(
"cscpID"
,
"cscpID"
,
"cscpID"
,
null
,
false
));
tableWP.Columns.Add(newColumn(
"cid"
,
"cID"
,
"c_cID"
,
null
,
false
));
tableWP.Columns.Add(newColumn(
"FirstMonth"
,
"First Month"
,
"c_FirstMonth"
,
"{0:MMM-yy}"
,
false
));
GridRelationFields drMain =
new
GridRelationFields();
drMain.MasterKeyField =
"id"
;
drMain.DetailKeyField =
"cscpID"
;
tableWP.ParentTableRelation.Add(drMain);
}
private
GridBoundColumn newColumn(
string
fieldName,
string
headerText,
string
Key,
string
format,
bool
hidden)
{
GridBoundColumn fld =
new
GridBoundColumn();
fld.DataField = fieldName;
fld.DataFormatString = format;
fld.HeaderText = headerText;
fld.Display = !hidden;
return
fld;
}
Please, any help is appreciated! Getting past this road block is crucial!