Click here to Skip to main content
12,998,892 members (31,524 online)
Rate this:
Please Sign up or sign in to vote.
Hi, All
I am using SPGridView in custom web part, but It is giving error here base.Render(writer)- error is-- (Web Part appears to be causing a problem. Unable to cast object of type 'Microsoft.SharePoint.WebControls.MenuTemplate' to type 'System.Web.UI.WebControls.Table'.)
Even I commented All SPMenuField code but prob. is persist same.
protected override void Render(HtmlTextWriter writer)
            using (SPSite _Site = new SPSite(SPContext.Current.Site.ID))
                using (SPWeb _Web = _Site.OpenWeb())
                            if (ChildControlsCreated)

Below is code example I am using.
spGridView and dataSource are my global object at class label.
protected override void CreateChildControls()
            dataSource = new ObjectDataSource();
            dataSource.ID = "dataSource";
            dataSource.SelectMethod = "GenerateTableTobindGrid";
            dataSource.TypeName = this.GetType().AssemblyQualifiedName;
            dataSource.ObjectCreating += new ObjectDataSourceObjectEventHandler(objectCreating);
            dataSource.Filtering += new ObjectDataSourceFilteringEventHandler(dataSource_Filtering);
            // SPGridView 
            spGridView = new SPGridView();
            spGridView.ID = "spGridView";
            spGridView.DataSourceID = dataSource.ID;
            spGridView.AutoGenerateColumns = false;
            spGridView.AllowPaging = true;
            spGridView.PageSize = 10;
            spGridView.AllowSorting = true;
            spGridView.EmptyDataText = string.Empty;
           SPMenuField nameCol1 = new SPMenuField();
            nameCol1.HeaderText = "Party";
            nameCol1.TextFields = "Party";
            nameCol1.NavigateUrlFields = "Party";
           nameCol1.SortExpression = "Party";
            nameCol1.MenuTemplateId = "menuTemplate";
           MenuTemplate menuTemplate = new MenuTemplate();
            menuTemplate.ID = "menuTemplate";
        MenuItemTemplate mitlUpdPaymt = new MenuItemTemplate("Open WebSite",         "~/_layouts/images/ASP16.GIF");
            //menuItemTemplate1.ClientOnClickNavigateUrl = "'%KEYWEBSITE%');";
            mitlUpdPaymt.ClientOnClickNavigateUrl = "javascript:OpenPopUp();";
          this.ChildControlsCreated = true;

If any idea please assist me..
Thanks in Advance.

Arun Kaushik
Posted 29-Aug-12 19:32pm
Updated 29-Aug-12 19:37pm

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170622.1 | Last Updated 30 Aug 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100