Hello,
I am trying to create a grid with 2-level self referencing hierarchy. However, the client does not have direct access to the database; it can only request a dataset for a given key. Is there any way to do this without looping through and loading the entire table into the dataset?
This is my current code (TCDataSet is inherited from the DataSet object):
Basically what I'm trying to do here is create a dataset for every master row, and then populate it when the row is expanded. When I click the 'expand' button, the grid seems to disappear.
I am trying to create a grid with 2-level self referencing hierarchy. However, the client does not have direct access to the database; it can only request a dataset for a given key. Is there any way to do this without looping through and loading the entire table into the dataset?
This is my current code (TCDataSet is inherited from the DataSet object):
protected void loadGrid() |
{ |
// Get the null level type codes |
TCDataSet typeCodeDataset = controller.GetTypeCode(null); |
DataView typeCodeDataview = typeCodeDataset.typecode.DefaultView; |
// Bind the RadGrid's top level view to the null level type codes |
RadGrid1.MasterTableView.DataSource = typeCodeDataview; |
RadGrid1.MasterTableView.DataKeyNames = new string[] { "type_code" }; |
RadGrid1.MasterTableView.EnableColumnsViewState = false; |
// Create datasets for sub level typecodes |
TCDataSet[] subTypeCodes = new TCDataSet[typeCodeDataview.Count]; |
DataView[] subTypeCodeViews = new DataView[typeCodeDataview.Count]; |
GridTableView[] subTypeCodeTableViews = new GridTableView[typeCodeDataview.Count]; |
for (int i = 0; i < typeCodeDataview.Count; i++) |
{ |
subTypeCodes[i] = new TCDataSet(); |
subTypeCodeViews[i] = subTypeCodes[i].typecode.DefaultView; |
subTypeCodeTableViews[i] = new GridTableView(); |
subTypeCodeTableViews[i].DataSource = subTypeCodeViews[i]; |
subTypeCodeTableViews[i].DataKeyNames = new string[2] { "type_code", "type_value" }; |
RadGrid1.MasterTableView.DetailTables.Insert(i, subTypeCodeTableViews[i]); |
GridBoundColumn subColumn = new GridBoundColumn(); |
RadGrid1.MasterTableView.DetailTables[i].Columns.Add(subColumn); |
subColumn.DataField = "type_code"; |
subColumn.HeaderText = "Type Code"; |
subColumn.HeaderStyle.Width = 80; |
} |
//Column to use to create the RadGrid columns |
GridBoundColumn boundColumn; |
//type_code column |
boundColumn = new GridBoundColumn(); |
RadGrid1.MasterTableView.Columns.Add(boundColumn); |
boundColumn.DataField = "type_code"; |
boundColumn.HeaderText = "Type Code"; |
boundColumn.HeaderStyle.Width = 80;//Unit.Pixel(20); |
//type_value column |
boundColumn = new GridBoundColumn(); |
RadGrid1.MasterTableView.Columns.Add(boundColumn); |
boundColumn.DataField = "type_value"; |
boundColumn.HeaderText = "Type Value"; |
boundColumn.HeaderStyle.Width = 80;// Unit.Pixel(30); |
int gridWidth = 0; |
for (int i = 0; i < RadGrid1.MasterTableView.Columns.Count; i++) |
{ |
gridWidth += (int)RadGrid1.MasterTableView.Columns[i].HeaderStyle.Width.Value; |
} |
RadGrid1.Width = gridWidth + 30; |
} |
protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) |
{ |
int index = e.Item.ItemIndex; |
subTypeCodes[index] = controller.GetTypeCode(typeCodeDataview[index]["type_value"].ToString()); |
subTypeCodeViews[index] = subTypeCodes[index].typecode.DefaultView; |
subTypeCodeTableViews[index].Rebind(); |
} |
Basically what I'm trying to do here is create a dataset for every master row, and then populate it when the row is expanded. When I click the 'expand' button, the grid seems to disappear.