This is a migrated thread and some comments may be shown as answers.

Rebind method throws SyntaxErrorException

3 Answers 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 22 Dec 2009, 08:01 PM
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.

    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?

3 Answers, 1 is accepted

Sort by
0
Josh
Top achievements
Rank 1
answered on 23 Dec 2009, 03:08 PM
Some additional info: I am using IE7. I tried putting the Rebind() inside a try/catch and IE gave me an error saying "'DataSourceCount' is not ready at this moment."
0
Tsvetoslav
Telerik team
answered on 28 Dec 2009, 01:03 PM
Hi Josh,

Try adding the parent-table-relation fields first:

subTypeCodeGrid.ParentTableRelation.Add(relationFields);

and then set their properties:

relationFields.MasterKeyField = "value";  
relationFields.DetailKeyField = "code";  

For further information, please, take a look at the following help articles:

http://www.telerik.com/help/aspnet-ajax/grdprogrammaticcreation.html
http://www.telerik.com/help/aspnet-ajax/mostcommonmistakes.html

Regards,
Tsvetoslav
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Josh
Top achievements
Rank 1
answered on 29 Dec 2009, 02:41 PM
Hello Tsvetoslav,

Thank you for your reply. I have switched to declarative definition for this grid and now it is working as intended.
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Josh
Top achievements
Rank 1
Tsvetoslav
Telerik team
Share this question
or