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

Telerik grid Calculated column

12 Answers 1338 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Kishan Gandikota
Top achievements
Rank 1
Kishan Gandikota asked on 05 Oct 2009, 10:14 AM
I've got a radGrid that allows paging.  I have a grid calculated column in the grid.  If user clicks on the next page or user changes the page size , the following error message displays:


Sys.WebForms.PageRequestManagerServerErrorException:  An item with the same key has already been added.

If we are commenting the grid calculated columns paging is working fine.

Thanks

12 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 05 Oct 2009, 04:26 PM
Hello Kishan,

Could you please elaborate a bit more on your scenario? Is it possible to have column with duplicate DataField? If you could share your grid declaration and any connected server code could help us provide a resolution for you. 

All the best,
Pavlina
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
Kishan Gandikota
Top achievements
Rank 1
answered on 07 Oct 2009, 05:59 AM

Please find the code for the Telerik grid.
Even after doing custom paging and custom sorting, I am getting the same error.

Default.aspx
 <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
        <telerik:RadGrid ID="RadGrid1" runat="server" EnableEmbeddedSkins="true" AllowPaging="True"
            AllowSorting="True" PageSize="2" GridLines="None" EnableLinqExpressions="false">
            <MasterTableView AutoGenerateColumns="False" AllowNaturalSort="false">
                <Columns>
                    <telerik:GridBoundColumn HeaderText="Account" UniqueName="AccountNumber" DataField="AccountNumber"
                        AllowSorting="true">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="TotalShares" DataField="TotalShares" HeaderText="Total No. of Shares"
                        DataType="System.Double">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn UniqueName="MarketValue" DataField="MarketValue" HeaderText="Market Value"
                        DataType="System.Double">
                    </telerik:GridBoundColumn>
                    <telerik:GridCalculatedColumn HeaderText="Total Price" DataFields="TotalShares, MarketValue"
                        Expression="{0}*{1}"  />
                </Columns>
            </MasterTableView>
        </telerik:RadGrid>

Default.aspx.cs

 protected void Page_Load(object sender, EventArgs e)
        {
            Page.Title = "RAD prototype";

            List<Account> accList = new List<Account>();
            Account acc = new Account();
            acc.AccountNumber = 123;
            acc.MarketValue = 120.32;
            acc.TotalShares = 100;
            accList.Add(acc);

            Account acc2 = new Account();
            acc2.AccountNumber = 123;
            acc2.MarketValue = 100.1;
            acc2.TotalShares = 12;
            accList.Add(acc2);

            Account acc3 = new Account();
            acc3.AccountNumber = 567;
            acc3.MarketValue = 2003.12;
            acc3.TotalShares = 91;
            accList.Add(acc3);

            Account acc4 = new Account();
            acc4.AccountNumber = 567;
            acc4.MarketValue = 102.3;
            acc4.TotalShares = 43;
            accList.Add(acc4);

            Account acc5 = new Account();
            acc5.AccountNumber = 912;
            acc5.MarketValue = 102.3;
            acc5.TotalShares = 43;
            accList.Add(acc5);

            Session["AccountValue"] = accList;

            RadGrid1.DataSource = Session["AccountValue"];
            RadGrid1.DataBind();
        }

Account.cs

public class Account
    {
        private long _accountNumber;
        private double _TotalShares;
        private double _MarketValue;

        public double TotalShares
        {
            get
            {
                return _TotalShares;
            }
            set
            {
                _TotalShares = value;
            }
        }

        public double MarketValue
        {
            get
            {
                return _MarketValue;
            }
            set
            {
                _MarketValue = value;
            }
        }

        public long AccountNumber
        {
            get
            {
                return _accountNumber;
            }
            set
            {
                _accountNumber = value;
            }
        }     
       
    }

0
Pavlina
Telerik team
answered on 07 Oct 2009, 05:45 PM
Hi Kishan,

But I have noticed that you are using Simple-DataBinding techniques(calling DataBind()). I would suggest you to use AdvanceDataBinding techniques. Try populating the Grid in the NeedDataSource event. Go through the following articles for getting more details about AdvanceDataBinding techniques.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/needdatasource/defaultcs.aspx
http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html

Best wishes,
Pavlina
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
Kishan Gandikota
Top achievements
Rank 1
answered on 08 Oct 2009, 02:45 AM
Hi Pavlina,

I tried using Advanced Data-binding technique. Still the problem persists.  Please note that the samples/demos given for GridCalculatedColumn doesn't have advanced data binding mechanism.

Where you able to see the problem with the sample that I have shared? Things are going fine if we are not using GridCalculatedColumn. So problem has to be with this. I have taken latest Telerik.web.dll and problem seems to be present with that also.

Please let me know how to proceed on this. Thanks.

Regards,
Kishan G K
0
Kishan Gandikota
Top achievements
Rank 1
answered on 12 Oct 2009, 07:06 PM
Hi Pavlina,

Did you get chance to look at this? Thanks.

Regards,
Kishan G K
0
Pavlina
Telerik team
answered on 13 Oct 2009, 04:53 PM
Hi Kishan,

At this point in order to progress in the resolution of this matter I will ask you to open a formal support ticket and send us a simple working project with reproduced this erroneous behavior. Thus we could do our best to help you further in resolving it.

Looking forward for your reply.

Kind regards,
Pavlina
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
Nirav Nayak
Top achievements
Rank 1
answered on 19 May 2010, 01:12 PM
Hi ,

I want to apply some string formatting instead of Calculation using two datafields. I can't use Templete column as I have to display same formated data in Google kind of filtering control also.

I am using two datafiled's - Date and User Count.  I have to display column like dd-MMM-YYYY(User Count)

so my column data will be

12-May-2010(10)
25-Jan-2010 (10)
12-May-2010(10)

Now when user click on Filtering control(Google style) I need to dispaly same formated data in google dropdown list so user can select and filter will work.
0
Pavlina
Telerik team
answered on 20 May 2010, 01:09 PM
Hi Nirav,

You can embed any content inside a RadComboBox template, including HTML markup and ASP.NET server controls, as well as other third party controls. Please refer to the following online example which demonstrates how to use the combobox templates:
http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx

Give it a try and let me know if it works for you.

Best wishes,
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
Nirav Nayak
Top achievements
Rank 1
answered on 27 May 2010, 10:53 AM
Hi Pavlina,

Thanks for the quick replay.

Well, still I am not able to achieve the task.

Let me make it simple. I have Datatable with datatime field and i want to display date in dd-MMM-yyyy formate in my radgrid and it allows user to filter using google style filtering.

Ex. 10-July-2010

In my datatable datawould be 07/10/2010 10:45:10AM
0
Pavlina
Telerik team
answered on 01 Jun 2010, 02:03 PM
Hi Nirav,

Please refer to the following forum thread which elaborates on this subject and see if it helps to achieve your goal:
http://www.telerik.com/community/forums/aspnet-ajax/grid/filtertemplate-with-date-and-time-filter.aspx

Best wishes,
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
Simone
Top achievements
Rank 1
answered on 13 Jul 2015, 08:59 AM

Hi Kishan,

I tried to execute your example. But I'd like to sum the 2 field and I'd like to avoid an error if one of the 2 fields is empty.

So I modified the code as following:

<telerik:GridCalculatedColumn HeaderText="Total Price" DataFields="TotalShares, MarketValue"
                        Expression="(({0} == null) ? 0 : {0})  + (({1} == null) ? 0 : {1})"  />

But when run the code I have this error on RadGrid1.DataBind() :

"Syntax error: Missing operand before '=' operator."

I don't know hot to solve this problem.

Someone can help me?

Thanks

0
Pavlina
Telerik team
answered on 16 Jul 2015, 11:25 AM
Hello,

Attached you can find a sample project where one of the columns has null values and the expression you provided is working without error. Give it a try and see what is the difference in your case.

Regards,
Pavlina
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Kishan Gandikota
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Kishan Gandikota
Top achievements
Rank 1
Nirav Nayak
Top achievements
Rank 1
Simone
Top achievements
Rank 1
Share this question
or