I have a RadGrid with two-level hierarchy for which the structure is defined programmatically. The datasource for the detail table is empty on page load. My idea was to query the database whenever an 'expand' event is fired and add the results to the datasource (which is held in viewstate). The event fires and the data is added to the datasource, but the Rebind() method throws the following exception:
Syntax error: Missing operand before 'Is' operator.
I tested the grid by loading some data on page load, so I know the NeedDataSource and DetailTableDataBind methods are working correctly. Some insight to why this is occurring would be appreciated. Sample code is provided below.
Also, when the 'expand' button is clicked, the 'RowClick' ItemCommand is fired instead of the desired ExpandCollapseCommandName. Any way to change this?
Syntax error: Missing operand before 'Is' operator.
I tested the grid by loading some data on page load, so I know the NeedDataSource and DetailTableDataBind methods are working correctly. Some insight to why this is occurring would be appreciated. Sample code is provided below.
protected void Page_Load(object sender, EventArgs e) |
{ |
if (!Page.IsPostBack) |
{ |
this.loadGrid(); |
} |
} |
protected void loadGrid() |
{ |
// Get the null level codes and sort according to display order |
dataset = controller.GetCode(null); |
// Set the keys |
RadGrid1.MasterTableView.DataKeyNames = new string[] { "code", "value" }; |
RadGrid1.MasterTableView.HierarchyLoadMode = GridChildLoadMode.Client; |
RadGrid1.ClientSettings.EnablePostBackOnRowClick = true; |
//Column to use to create the RadGrid columns |
GridBoundColumn boundColumn; |
//code column |
boundColumn = new GridBoundColumn(); |
RadGrid1.MasterTableView.Columns.Add(boundColumn); |
boundColumn.DataField = "code"; |
boundColumn.HeaderText = "Code"; |
boundColumn.HeaderStyle.Width = 80; |
//value column |
boundColumn = new GridBoundColumn(); |
RadGrid1.MasterTableView.Columns.Add(boundColumn); |
boundColumn.DataField = "value"; |
boundColumn.HeaderText = "Value"; |
boundColumn.HeaderStyle.Width = 80; |
// Create dataset for sub level codes |
subDataset = new DataSet(); |
GridTableView subGrid = new GridTableView(RadGrid1); |
subTypeCodeGrid.Name = "SubCodes"; |
subTypeCodeGrid.DataKeyNames = new string[] { "code", "value" }; |
subTypeCodeGrid.AutoGenerateColumns = false; |
GridRelationFields relationFields = new GridRelationFields(); |
relationFields.MasterKeyField = "value"; |
relationFields.DetailKeyField = "code"; |
subTypeCodeGrid.ParentTableRelation.Add(relationFields); |
RadGrid1.MasterTableView.DetailTables.Add(subGrid); |
// Add columns to sub dataset |
//code column |
boundColumn = new GridBoundColumn(); |
subTypeCodeGrid.Columns.Add(boundColumn); |
boundColumn.DataField = "code"; |
boundColumn.HeaderText = "Code"; |
boundColumn.HeaderStyle.Width = 80; |
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, Telerik.Web.UI.GridCommandEventArgs e) |
{ |
int index = e.Item.ItemIndex; |
if ((e.CommandName == RadGrid.ExpandCollapseCommandName || e.CommandName == "RowClick")) |
{ |
string Value = RadGrid1.MasterTableView.Items[index]["value"].Text.ToString().Trim(); |
if (loadedValues.Contains(Value)) |
{ |
return; |
} |
else |
{ |
loadedValues.Add(Value); |
DataSet tempSubCodes = controller.GetCode(Value); |
foreach (DataSet.table1Row row in tempSubCodes.table1) |
{ |
subDataset.table1.Rows.Add(row.ItemArray); |
} |
RadGrid1.Rebind(); //<-- ERROR |
} |
RadGrid1.MasterTableView.Items[index].Expanded = true; |
} |
} |
protected void RadGrid1_NeedDataSource(object source, GridNeedDataSourceEventArgs e) |
{ |
if (!e.IsFromDetailTable) |
{ |
RadGrid1.DataSource = dataset.table1.DefaultView; |
} |
} |
protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e) |
{ |
switch (e.DetailTableView.Name) |
{ |
case "SubCodes": |
{ |
e.DetailTableView.DataSource = subDataset.table1.DefaultView; |
break; |
} |
} |
} |
Also, when the 'expand' button is clicked, the 'RowClick' ItemCommand is fired instead of the desired ExpandCollapseCommandName. Any way to change this?