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

Having problem in creating grid programmatically

4 Answers 102 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Muhammad Farjad
Top achievements
Rank 1
Muhammad Farjad asked on 06 Apr 2010, 07:23 PM

Hi,

I need to create hierarchical rad grid programatically using DataTable, but I'm having a problem in settng the data source for level 1 hierarchy. When I try to expand the child table, an exception is thrown as
 
"Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand before 'Is' operator."

Kindly help me out regarding this issue. I have attached my code and exception trace. Thanks

Regards
Muhammad Farjad

----------------------------------------------------------------------------------------------------------------------------------------------------------------------

<body>

 

     <form id="form1" runat="server">

 

         <telerik:RadScriptManager ID="RadScriptManager1" runat="server">

 

             <Scripts>

 

                 <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />

 

                <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />

 

             </Scripts
        
</telerik:RadScriptManager>

 

        <telerik:RadAjaxManager ID="RadAjaxManager1" runat="server">

         </telerik:RadAjaxManager>

 

        <div>

 

             <telerik:RadGrid ID="RadGrid1" runat="server" ondetailtabledatabind="RadGrid1_DetailTableDataBind">

 

              </telerik:RadGrid>

         </div>

 

    </form>

 </body>

---------------------------------------------------- Code Behind File ----------------------------------------------------------------------------

using
System;

 

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.Data;

using System.Configuration;

using System.Web.Security;

using System.Web.UI.WebControls.WebParts;

using System.Web.UI.HtmlControls;

using Telerik.Web.UI;

 

public partial class Default : System.Web.UI.Page

    protected void Page_Load(object sender, EventArgs e) 
    {

         if (!IsPostBack)

         {

             //Add grand father table

             DataTable grandFatherTable = CreateDataTable("GrandFather");

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

             AddDataToTable("usman", "Usman", "Mansur", grandFatherTable);

             AddDataToTable("adnan", "Adnan", "Ahmad", grandFatherTable);

             AddDataToTable("nabeel", "Nabeel", "Ahmed", grandFatherTable);

 

              RadGrid1.DataSource = grandFatherTable;

              RadGrid1.MasterTableView.DataKeyNames = new string[] { "username" };

              RadGrid1.Width = Unit.Percentage(98);

              RadGrid1.PageSize = 5;

              RadGrid1.AllowPaging = true;

 

               //RadGrid1.PagerStyle.Mode = GridPagerMode.NextPrevAndNumeric;

               RadGrid1.AutoGenerateColumns = false;

 

 

 

 

 

 

 

 

 

 

 

 

               RadGrid1.Skin = "Web20";

 

                RadGrid1.MasterTableView.PageSize = 15;

                RadGrid1.MasterTableView.Width = Unit.Percentage(100);

                GridBoundColumn boundColumn;

                boundColumn = new GridBoundColumn();

 

                RadGrid1.MasterTableView.Columns.Add(boundColumn);

                boundColumn.DataField = "username";

                 boundColumn.HeaderText = "User Name";

                 boundColumn = new GridBoundColumn();

 

                    RadGrid1.MasterTableView.Columns.Add(boundColumn);

                    boundColumn.DataField = "firstname";

                    boundColumn.HeaderText = "First Name";

                     boundColumn = new GridBoundColumn();

 

                    RadGrid1.MasterTableView.Columns.Add(boundColumn);

                    boundColumn.DataField = "lastname";

                    boundColumn.HeaderText = "Last Name";

 

                     //Add Father table

                     DataTable fatherTable = CreateDataTable("Father");

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

                     AddDataToTable("usman", "u1", "u2", fatherTable);

                     AddDataToTable("adnan", "a1", "a2", fatherTable);

                     AddDataToTable("nabeel", "n1", "n2", fatherTable);

 

                    GridTableView tableViewFather = new GridTableView(RadGrid1);

                     tableViewFather.Width = Unit.Percentage(100);

                    tableViewFather.DataSource = fatherTable;

                    tableViewFather.DataKeyNames = new string[] { "username" };

 

                    GridRelationFields relationFields = new GridRelationFields();

                     relationFields.MasterKeyField = "username";

                     relationFields.DetailKeyField = "username";

 

                        tableViewFather.ParentTableRelation.Add(relationFields);

                        RadGrid1.MasterTableView.DetailTables.Add(tableViewFather);

                        boundColumn = new GridBoundColumn();

                        tableViewFather.Columns.Add(boundColumn);

                        boundColumn.DataField = "username";

                         boundColumn.HeaderText = "User Name";

 

                            boundColumn = new GridBoundColumn();

                             tableViewFather.Columns.Add(boundColumn);

                            boundColumn.DataField = "firstname";

                            boundColumn.HeaderText = "First Name";

                             
                            boundColumn = new GridBoundColumn();

                             tableViewFather.Columns.Add(boundColumn);

                            boundColumn.DataField = "lastname";

                             boundColumn.HeaderText ="Last Name";

        }
    }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

    private DataTable CreateDataTable(string tableName)

     {   

            DataTable myDataTable = new DataTable(tableName);

             DataColumn myDataColumn;

             myDataColumn = new DataColumn();

             myDataColumn.DataType = Type.GetType("System.String");

 

            myDataColumn.ColumnName = "username";

 

            myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();

            myDataColumn.DataType = Type.GetType("System.String");

             myDataColumn.ColumnName = "firstname";

             myDataTable.Columns.Add(myDataColumn);

            myDataColumn = new DataColumn();

             myDataColumn.DataType = Type.GetType("System.String");

             myDataColumn.ColumnName = "lastname";

             myDataTable.Columns.Add(myDataColumn);

             return myDataTable;

     }

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

    private void AddDataToTable(string username, string firstname, string lastname, DataTable myTable)

     {

        DataRow row;

        row = myTable.NewRow();

         //row["id"] = Guid.NewGuid().ToString();

         row["username"] = username;

 

 

 

 

         row["firstname"] = firstname;

         row["lastname"] = lastname;

         myTable.Rows.Add(row);

    }

 

 

 

 

 

 

 

    protected void RadGrid1_DetailTableDataBind(object source, GridDetailTableDataBindEventArgs e)

     {

        DataTable fatherTable = CreateDataTable("Father");

         AddDataToTable("usman", "u1", "u2", fatherTable);

         AddDataToTable("adnan", "a1", "a2", fatherTable);

         AddDataToTable("nabeel", "n1", "n2", fatherTable);

         e.DetailTableView.DataSource = fatherTable;

    }

}

 

 

 

 

 

 

 

 

 

 

 

 

---------------------------------------------------------- exception ------------------------------------------------------------------------

Server Error in '/RadHierarchicalGrid' Application.
--------------------------------------------------------------------------------

Syntax error: Missing operand before 'Is' operator.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SyntaxErrorException: Syntax error: Missing operand before 'Is' operator.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace:

[SyntaxErrorException: Syntax error: Missing operand before 'Is' operator.]
   System.Data.ExpressionParser.Parse() +4824040
   System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +121
   System.Data.DataView.set_RowFilter(String value) +153
   System.Data.LinqDataView.set_RowFilter(String value) +53
   Telerik.Web.UI.GridEnumerableFromDataView.PerformTransformation() +375
   Telerik.Web.UI.GridEnumerableFromDataView.TransformEnumerable() +21
   Telerik.Web.UI.GridTableView.GetEnumerator(Boolean useDataSource, GridEnumerableBase resolvedDataSource, ArrayList dataKeysArray) +105
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +432
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +500
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +57
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +114
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +31
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +142
   Telerik.Web.UI.GridTableView.PerformSelect() +4
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +73
   Telerik.Web.UI.GridTableView.DataBind() +224
   Telerik.Web.UI.GridDataItem.OnExpand() +272
   Telerik.Web.UI.GridItem.set_Expanded(Boolean value) +109
   Telerik.Web.UI.GridExpandCommandEventArgs.ExecuteCommand(Object source) +34
   Telerik.Web.UI.RadGrid.OnBubbleEvent(Object source, EventArgs e) +134
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   Telerik.Web.UI.GridItem.OnBubbleEvent(Object source, EventArgs e) +115
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.Button.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +166
   System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +36
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565

 

--------------------------------------------------------------------------------
Version Information: Microsoft .NET Framework Version:2.0.50727.4927; ASP.NET Version:2.0.50727.4927

4 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 07 Apr 2010, 12:43 PM
Hi Muhammad,

I checked your account and it occurs that you have opened support ticket and several forum threads for the same thing. It is highly recommended that you keep related questions in one support thread or a forum post, so that we can easily keep track of your support history and provide better answers in a shorter time.

Regards,
Pavlina
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Muhammad Farjad
Top achievements
Rank 1
answered on 07 Apr 2010, 02:43 PM
I am sorry for that, actually I badly needed the help as earlier as possible that's why I did so. Thanks any way.
0
Bruno
Top achievements
Rank 2
answered on 07 Apr 2010, 08:26 PM
Hi

this is Bruno and i recommend det you use a need data source - tis very convenient and easy to using

i also thing you can use detail tabledata binding events i used this help to help me
http://www.telerik.com/help/aspnet-ajax/grdhierarchicaldatabindingusingdetailtabledatabind.html

tanks



0
Muhammad Farjad
Top achievements
Rank 1
answered on 08 Apr 2010, 04:06 AM
Thanks Bruno, your advice is helpful. Thanks a lot.
Tags
Grid
Asked by
Muhammad Farjad
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Muhammad Farjad
Top achievements
Rank 1
Bruno
Top achievements
Rank 2
Share this question
or