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

GridCalculatedColumn error "operator * cannot be applied for string"

2 Answers 85 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Venkatesh
Top achievements
Rank 1
Venkatesh asked on 07 Dec 2012, 02:11 PM
Hi,
In my aspx page, i have the below columns:
<telerik:GridTemplateColumn DataField="OrderQuantity" HeaderText="Order Quantity"
                   UniqueName="OrderQuantity" Visible="true">
                   <InsertItemTemplate>
                       <telerik:RadTextBox ID="RadtxtOrderQuantity" runat="server" Text='<%# Bind("OrderQuantity") %>'>
                       </telerik:RadTextBox>
                   </InsertItemTemplate>
                   <EditItemTemplate>
                       <telerik:RadTextBox ID="RadtxtOrderQuantity" runat="server" Text='<%# Eval("OrderQuantity") %>'>
                       </telerik:RadTextBox>
                   </EditItemTemplate>
                   <ItemTemplate>
                       <telerik:RadTextBox ID="RadtxtOrderQuantity" ReadOnly="true" runat="server" Text='<%# Eval("OrderQuantity") %>' />
                   </ItemTemplate>
               </telerik:GridTemplateColumn>
               <telerik:GridTemplateColumn DataField="UnitPrice" HeaderText="Unit Price" UniqueName="UnitPrice"
                   Visible="true">
                   <InsertItemTemplate>
                       <telerik:RadNumericTextBox ID="RadtxtUnitPrice" runat="server" Text='<%# Bind("UnitPrice") %>'>
                       </telerik:RadNumericTextBox>
                   </InsertItemTemplate>
                   <EditItemTemplate>
                       <telerik:RadNumericTextBox ID="RadtxtUnitPrice" runat="server" Text='<%# Eval("UnitPrice") %>'>
                       </telerik:RadNumericTextBox>
                   </EditItemTemplate>
                   <ItemTemplate>
                       <telerik:RadNumericTextBox ID="RadtxtUnitPrice" Type="Currency" ReadOnly="true" runat="server"
                           Text='<%# Eval("UnitPrice") %>' />
                   </ItemTemplate>
               </telerik:GridTemplateColumn>
               <telerik:GridCalculatedColumn DataFormatString="{0:C}" DataType="System.Double" HeaderText="Extended Price"
                   UniqueName="ExtendedPrice" DataFields="OrderQuantity,UnitPrice" Expression="{0}*{1}"
                   FooterText="Total : " Aggregate="Sum">
               </telerik:GridCalculatedColumn>

When the page loads, i am binding the grid with empty datatable:
private DataTable CreateEmptyTable()
        {
            DataTable dt = new DataTable("PurchaseData");
              
            try
            {
                  
                dt.Columns.Add(new DataColumn("OrderQuantity"));
                dt.Columns.Add(new DataColumn("UnitPrice"));
                dt.Columns.Add(new DataColumn("ExtendedPrice"));
  
                DataRow dr = dt.NewRow();
                  
                dr["OrderQuantity"] = 0;
                dr["UnitPrice"] = 0;
                dr["ExtendedPrice"] = 0;
                dt.Rows.Add(dr);
  
            }
            catch (Exception)
            {
                  
                throw;
            }
            return dt;
        }
  
bindgrid()
{
 radgrid1.DataSource = CreateEmptyTable();
 radgrid1.DataBind();
}

I am getting the error as "operator * cannot be applied between string and string".
The columns are integer type in sql.  How to to fix this?
Thanks

2 Answers, 1 is accepted

Sort by
0
Venkatesh
Top achievements
Rank 1
answered on 10 Dec 2012, 09:07 AM
HI,
Any help on this issue?
0
Accepted
Antonio Stoilkov
Telerik team
answered on 12 Dec 2012, 07:09 AM
Hello Venkatesh,

In order to resolve your issue you should specify the DataColumn objects its DataType property so the RadGrid knows what the column types are.
DataTable dt = new DataTable("PurchaseData");
               
try
{
                   
    dt.Columns.Add(new DataColumn("OrderQuantity") { DataType = typeof(int) });
    dt.Columns.Add(new DataColumn("UnitPrice") { DataType = typeof(int) });
    dt.Columns.Add(new DataColumn("ExtendedPrice") { DataType = typeof(int) });
   
    DataRow dr = dt.NewRow();
                   
    dr["OrderQuantity"] = 0;
    dr["UnitPrice"] = 0;
    dr["ExtendedPrice"] = 0;
    dt.Rows.Add(dr);
   
}
catch (Exception)
{
                   
    throw;
}
return dt;

Regards,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Venkatesh
Top achievements
Rank 1
Answers by
Venkatesh
Top achievements
Rank 1
Antonio Stoilkov
Telerik team
Share this question
or