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

Sys.WebForms.PageRequestManagerServerErrorException: cannot find column [xxxxxx]

2 Answers 214 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Felix Ruben Melendez Batres
Top achievements
Rank 1
Felix Ruben Melendez Batres asked on 16 Mar 2011, 05:10 AM

Hi there,

I'm loading a RadGrid with AutoGenerateColumns="true", for databinding I'm using NeedDataSource(...) event handler. Since I want to format values from some columns I use the ColumnCreated(...) event handler. I also want to do some Aggregation based on  the type of column. For this, I have the following helper method:

public static void ColumnCreated(object sender, Telerik.Web.UI.GridColumnCreatedEventArgs e)
        {
           
            if(!string.IsNullOrEmpty(e.Column.UniqueName))
            {
                GridBoundColumn gbc = e.Column as GridBoundColumn;

                if (gbc != null)
                {
                    gbc.HeaderStyle.HorizontalAlign = HorizontalAlign.Center;

                    gbc.HeaderText = gbc.UniqueName.ToUpper() == "EXPANDCOLUMN" ? string.Empty : gbc.UniqueName;

                    switch (gbc.DataTypeName.ToUpper())
                    {
                        case "SYSTEM.DATETIME":
                            gbc.DataFormatString = "{0:d}";
                            break;
                        case "SYSTEM.DECIMAL":
                            gbc.DataFormatString = "{0:N2}";
                            gbc.Aggregate = GridAggregateFunction.Sum;
                            gbc.ItemStyle.HorizontalAlign = HorizontalAlign.Right;
                            gbc.FooterStyle.HorizontalAlign = HorizontalAlign.Right;
                            break;
                    }
                }               
            }
        }

But when this event fires something real "weird" is happening. I keep getting the following error:

Microsoft JScript runtime error:
Sys.WebForms.PageRequestManagerServerErrorException: cannot find column [xxxxxx].

When I mean "weird" is that such column does exist!.

On the other hand, when I comment out the logic inside ColumnCreated(...) event, the error does not show up. But as you might expect... the values are not formatted as well as there is no Aggregation on the columns that I want, and I do really want the event to fire since I need to do some formatting on the values of certain columns.

Thanks in advance,

Felix


Today, I tried a different approach.  This time I used the ItemDataBound(...) event.

The code now is as follows:

protected void gvwOperaciones_ItemDataBound(object sender, GridItemEventArgs e)
    {
        if(e.Item.ItemType == GridItemType.AlternatingItem ||
            e.Item.ItemType == GridItemType.Item)
        {
            int colIndex = 0;
            DataRowView drv = e.Item.DataItem as DataRowView;

            foreach (DataColumn dc in drv.DataView.Table.Columns)
            {
                GridDataItem gdi = e.Item as GridDataItem;
                switch (dc.DataType.ToString().ToUpper())
                {
                    case "SYSTEM.DATETIME":
                        gdi[dc.ColumnName].Text = string.Format("{0:d}", drv[dc.ColumnName]);                       
                        break;
                    case "SYSTEM.DECIMAL":
                        gdi[dc.ColumnName].Text = string.Format("{0:N2}", drv[dc.ColumnName]);
                        GridBoundColumn gbc = gvwOperaciones.MasterTableView.AutoGeneratedColumns[colIndex] as GridBoundColumn;
                        if(gbc != null)
                            gbc.Aggregate = GridAggregateFunction.Sum;
                        break;
                    default:
                        break;
                }
                colIndex++;
            }
        }
    }


But something interesting again!!!, this time if I comment out the lines:

GridBoundColumn gbc = gvwOperaciones.MasterTableView.AutoGeneratedColumns[colIndex] as GridBoundColumn;
if(gbc != null)
    gbc.Aggregate = GridAggregateFunction.Sum;


It works! but remember that the aggregation Does not occur!!!

Now as soon as I put them back again, the aforementioned error in javascript pops up again!!! 

Question:
Is it bug in RadGrid? Am I not coding the right way?

This is really driving me nuts! :-( Can some one, please shed some light on this?

Felix

2 Answers, 1 is accepted

Sort by
0
Maria Ilieva
Telerik team
answered on 21 Mar 2011, 10:30 AM
Hi Felix,

Can you try out the following code to set the aggregate function for columns:
protected void RadGrid1_ColumnCreated(object sender, GridColumnCreatedEventArgs e)   
    {   
        if (e.Column is GridBoundColumn)   
        {   
            (e.Column as GridBoundColumn).Aggregate = GridAggregateFunction.Count;   
        }   
    }   

Also please ensure that the ShowFooter property of the grid to true.


All the best,
Maria Ilieva
the Telerik team
0
Felix Ruben Melendez Batres
Top achievements
Rank 1
answered on 21 Mar 2011, 11:16 PM
Maria,

Thanks for your answer. I don't know but for some reason when I started to play with some Telerik web controls (for example, I wanted to add RadAjaxManagerProxy to some user controls), the aforementioned error popped up. Then I deleted the RadAjaxManagerProxy web control but the error always was shown. Since I had a backup of the project, I restored the project to one that worked and then it all executed as expected. 

On the other hand, I also tried your code and it work good as well. So as you might see, yours and the code I wrote both worked OK.

Thanks again,

Felix
Tags
Grid
Asked by
Felix Ruben Melendez Batres
Top achievements
Rank 1
Answers by
Maria Ilieva
Telerik team
Felix Ruben Melendez Batres
Top achievements
Rank 1
Share this question
or