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

RadGrid Rebind and CalculatedColumn

5 Answers 166 Views
Grid
This is a migrated thread and some comments may be shown as answers.
robertw102
Top achievements
Rank 1
robertw102 asked on 17 Feb 2009, 08:14 PM
I've noticed a problem with the RadGrid control when I call rebind and I have a calculated column in the my grid.

I'm trying to use the AjaxManager example you show in your online documentation on rebinding the grid by using the AjaxManager's AjaxRequest to rebind the grid when the RadWindow gets closed. The problem I'm getting is that when the ajax request is called the first time after the RadWindow object is closed nothing happens to the grid, only subsequent requests does the code work.

I looked at the code and it appears that on the first request it throws an error "An item with the same key already exists" from the grid control, which is the same error I received from another application which I reported to you when I used rebind in the delete command. I understand that it's unneccesary to call rebind in the delete command, but calling rebind in another event that has nothing to do with the grid it still throws that error.

Is there some bug with the calculated column that prevents rebind to be called twice in a row or something? If you could suggest a work-around for this situation that would be great.

5 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 20 Feb 2009, 02:19 PM
Hi,

Can you please post the code implementation, so that I can try and replicate the issue locally?

Sincerely yours,
Yavor
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
robertw102
Top achievements
Rank 1
answered on 16 Mar 2009, 02:19 PM
Sorry for taking so long to reply, but here is an example. It may not be practical, but it gets the point across.

ASPX Page:
<telerik:RadGrid ID="grdTest" runat="server" AutoGenerateColumns="False" GridLines="None"
            <MasterTableView CellSpacing="-1"
                <RowIndicatorColumn> 
                    <HeaderStyle Width="20px" /> 
                </RowIndicatorColumn> 
                <ExpandCollapseColumn> 
                    <HeaderStyle Width="20px" /> 
                </ExpandCollapseColumn> 
                <Columns> 
                    <telerik:GridBoundColumn DataField="ColumnID" HeaderText="Column ID" UniqueName="column"
                    </telerik:GridBoundColumn> 
                    <telerik:GridCalculatedColumn Aggregate="Sum" DataFields="Tax,SubTotal" Expression="{0}+{1}" 
                        HeaderText="Calculated Value" UniqueName="column1"
                    </telerik:GridCalculatedColumn> 
                </Columns> 
            </MasterTableView> 
        </telerik:RadGrid> 
        <br /> 
        <asp:Button ID="btnRebind" runat="server" Text="Rebind Grid" /> 
Code-Behind:
Protected Sub grdTest_NeedDataSource(ByVal source As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdTest.NeedDataSource 
        'create table 
        Dim dtTest As DataTable = New DataTable() 
 
        'build table 
        With dtTest.Columns 
            .Add("ColumnID", GetType(Integer)) 
            .Add("Tax", GetType(Decimal)) 
            .Add("SubTotal", GetType(Decimal)) 
        End With 
 
        'first row 
        Dim drFirst As DataRow = dtTest.NewRow() 
        drFirst("ColumnID") = 1 
        drFirst("Tax") = 13.25 
        drFirst("SubTotal") = 50.84 
 
        'second row 
        Dim drSecond As DataRow = dtTest.NewRow() 
        drSecond("ColumnID") = 2 
        drSecond("Tax") = 15 
        drSecond("SubTotal") = 38.74 
 
        'add to table 
        dtTest.Rows.Add(drFirst) 
        dtTest.Rows.Add(drSecond) 
 
        'bind to grid 
        Me.grdTest.DataSource = dtTest 
    End Sub 
 
    Protected Sub btnRebind_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnRebind.Click 
        'rebind the grid 
        Me.grdTest.Rebind() 
        Me.grdTest.Rebind() 
    End Sub 

I've run this test example and returns the error I get when two rebinds happen in the same request, either if I call it explicitly or RadGrid decides to rebind itself, when I have calculated columns in the grid.

Also, to note, I have tested this out on the latest version of the ASP.NET AJAX RadControls 2009.01.0311.20 with the same result.

Thanks
0
Yavor
Telerik team
answered on 19 Mar 2009, 08:22 AM
Hello,

I tested the setup which you outlined, and the control behaved as expected.
Attached to this message, you will find the code, which I used for testing.
Take a look at it and let me know if this is the expected behavior, or if I am leaving something out.

Sincerely yours,
Yavor
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
robertw102
Top achievements
Rank 1
answered on 23 Mar 2009, 02:47 PM
Hi,

I tried your example and it worked like I was expecting it. Now, when I removed your Telerik trial bin files and put in my purchased Telerik bin files, that's when I saw the error message I was getting. If you could test it out with the purchased version, instead of the Trial version, because the purchased one seems to be the one that throws the error.

The version I'm using is 2009.01.0311.20 and the one you gave me in the example is 2009.01.0311.35. So I have to assume that's the reason why yours works correctly and mine doesn't.

Thanks.
0
Yavor
Telerik team
answered on 26 Mar 2009, 11:40 AM
Hi,

I tested with the dev version as well, and sure enough, the control behaved as expected.
If the issue persists, you can open a formal support ticket, and send us a small working project, demonstrating your setup, along with the unwanted behavior. I will debug it locally, and advise you further.

Best wishes,
Yavor
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
robertw102
Top achievements
Rank 1
Answers by
Yavor
Telerik team
robertw102
Top achievements
Rank 1
Share this question
or