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

server side event for cell changed

7 Answers 126 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Elliott
Top achievements
Rank 2
Elliott asked on 11 Jul 2011, 04:40 PM
I'm trying to reproduce the behavior of a pre-existing grid which opens up only 2 columns for updating:  a date and a quantity
if either of them is changed the back end database is updated
I used a template with a label in the ItemTemplate and a RadNumericTextBox in the EditItemTemplate and triggered the update on the quantity changed event for the quantity
but... then the automatic aggregate didn't work - and there is a lot of filtering possible
my kluge is to have 2 quantity columns - one read only for the total and the other a template with only the EditItemTemplate

is there a way to update the quantity with only one column and still aggregate without a lot of extra code?

7 Answers, 1 is accepted

Sort by
0
Veli
Telerik team
answered on 14 Jul 2011, 09:53 AM
Hello Marianne,

Can you, please show us some sample code demonstrating the approach you have taken? What do you mean by "then the automatic aggregate didn't work", are your data values updated but the aggregates don't, or your data values are not updated at all (indicating data update is unsuccessful). Also, can you, please, show us how do you update the grid when the quantity changes in the textbox?

Greetings,
Veli
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Elliott
Top achievements
Rank 2
answered on 14 Jul 2011, 01:37 PM
my solution is to have 2 quantity columns - one of which opens up when the row is clicked or double clicked
the EditItemTemplate has a RADNumericTextBox and the update is done on the Changed event
<telerik:RadGrid ID="rgEditOrder" OnNeedDataSource="rgEditOrder_NeedDataSource" OnItemCommand="rgEditOrder_ItemCommand" OnItemCreated="rgEditOrder_ItemCreated" ShowFooter="True" runat="server">
<GroupingSettings CaseSensitive="false" />
<MasterTableView DataKeyNames="OrderSeq" AutoGenerateColumns="false" AllowSorting="true" AllowPaging="true" AllowFilteringByColumn="False" EditMode="InPlace" >
<Columns>
    <telerik:GridBoundColumn UniqueName="StoreNumber" DataField="StoreNumber" HeaderText="Store #" DataFormatString="{0:#####}" DataType="System.Int32" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="40px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="BoothNumber" DataField="BoothNumber" HeaderText="Booth #" DataFormatString="{0:#####}" DataType="System.Int32" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="40px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="ItemID" DataField="ItemID" HeaderText="Item" DataType="System.Double" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="40px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="ItemDescription" DataField="ItemDescription" HeaderText="Description" ReadOnly="True">
        <HeaderStyle Width="100px" />
    </telerik:GridBoundColumn>
    <telerik:GridDateTimeColumn UniqueName="ShipDate" DataField="ShipDate" PickerType="DatePicker" HeaderText="Ship Date" DataFormatString="{0:d}" DataType="System.DateTime" >
        <HeaderStyle Width="60px" />          
    </telerik:GridDateTimeColumn>
    <telerik:GridTemplateColumn UniqueName="Cases" HeaderText="" >
        <EditItemTemplate>
            <telerik:RadNumericTextBox ID="rntbQty" Text='<%# Eval("Qty") %>' MinValue='<%# Bind("Qty") %>' OnTextChanged="rntbQty_TextChanged" AutoPostBack="True" Width="30px" runat="server">
                <NumberFormat DecimalDigits="0" />
            </telerik:RadNumericTextBox>
        </EditItemTemplate>
        <HeaderStyle Width="30px" />           
    </telerik:GridTemplateColumn>
    <telerik:GridBoundColumn UniqueName="Qty" DataField="Qty" HeaderText="Cases" DataFormatString="{0:#####}" DataType="System.Int32" Aggregate="Sum" ReadOnly="True" >
        <HeaderStyle Width="30px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="NetCost" DataField="NetCost" HeaderText="Net Cost" DataFormatString="{0:C2}" DataType="System.Double" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="ItemTotal" DataField="ItemTotal" HeaderText="Item Total" DataFormatString="{0:C2}" DataType="System.Double" Aggregate="Sum" ReadOnly="True">
        <HeaderStyle Width="50px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="PageNumber" DataField="PageNumber" HeaderText="Page" DataFormatString="{0:#####}" DataType="System.Int32" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="40px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="VendorNumber" DataField="VendorNumber" HeaderText="Vendor" DataFormatString="{0:#####}" DataType="System.Int32" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="40px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="DepartmentNumber" DataField="DepartmentNumber" HeaderText="Depart" DataFormatString="{0:##}" DataType="System.Int32" Aggregate="None" ReadOnly="True">
        <HeaderStyle Width="30px" />
    </telerik:GridBoundColumn>
    <telerik:GridBoundColumn UniqueName="OrderSeq" DataField="OrderSeq" DataType="System.Int64" Visible="false">
    </telerik:GridBoundColumn>
</Columns>
</MasterTableView>
<ClientSettings>
    <ClientEvents OnRowDblClick="RowDblClick" />
    <ClientEvents OnRowClick="RowClick" />
</ClientSettings>
</telerik:RadGrid>

these go in a RADCodeBlock

function RowDblClick(sender, eventArgs) {
    idx = eventArgs.get_itemIndexHierarchical();
    sender.get_masterTableView().editItem(idx);
    }
function RowClick(sender, eventArgs) {
    idx = eventArgs.get_itemIndexHierarchical();
    sender.get_masterTableView().editItem(idx);
    }

protected void rgEditOrder_NeedDataSource(object source, GridNeedDataSourceEventArgs e)
{
    DataSet dsOrder = new DataSet();
    if (txtStoreHidden.Value == "")
    {
        return;
    }
    WsOrderSystem wsOrder = new WsOrderSystem();
    dsOrder = wsOrder.GetOnlineOrder(Convert.ToDouble(txtStoreHidden.Value), txtChain.Value);
    rgEditOrder.DataSource = dsOrder;
    Session["EditOrderView"] = dsOrder;
}
protected void rntbQty_TextChanged(object sender, EventArgs e)
{
    RadNumericTextBox rntbQty;
    GridDataItem gdItem;
    GridEditableItem geItem;
    DateTime ShipDate;
    int Qty,iBooth,iPage,iConsolid;
    double fStore,dVendor,dItemID,dNetCost;
    string[] strDel = new string[1];
    double[] dQty = new double[1];
    Hashtable CornedBeef;
    WsOrderSystem wsOrder;
    bool bUpdate = false;
 
    rntbQty = (RadNumericTextBox)sender;
    gdItem = rntbQty.NamingContainer as GridDataItem;
    geItem = rntbQty.NamingContainer as GridEditableItem;
    CornedBeef = new Hashtable();
    gdItem.ExtractValues(CornedBeef);
    ShipDate = Convert.ToDateTime(CornedBeef["ShipDate"]);
    Qty = Convert.ToInt32(rntbQty.Value);
    fStore = Convert.ToDouble(ExtractValue(geItem, "StoreNumber"));
    iBooth = Convert.ToInt32(ExtractValue(geItem, "BoothNumber"));
    iPage = Convert.ToInt32(ExtractValue(geItem, "PageNumber"));
    dVendor = Convert.ToDouble(ExtractValue(geItem, "VendorNumber"));
    dNetCost = Convert.ToDouble(ExtractValue(geItem, "NetCost"));       
    dItemID = Convert.ToDouble(ExtractValue(geItem, "ItemID"));
    iConsolid = Convert.ToInt32(txtConsolid.Value);
    strDel[0] = ShipDate.ToShortDateString();
    dQty[0] = Qty;
    wsOrder = new WsOrderSystem();
    bUpdate = wsOrder.AddToOrder(fStore,iBooth,iPage,dVendor,dNetCost,dItemID,strDel,dQty,true,iConsolid);
}
 
protected void rdpShipDate_SelectedDateChanged(object sender, EventArgs e)
{
    RadDatePicker rdpShipDate;
    GridEditableItem geItem;
    DateTime OldShipDate,NewShipDate;
    double fStore,dItemID;
    int iBooth,iPage;
    string strOldDel,strNewDel;
    bool bUpdate=false;
    WsOrderSystem wsOrder;
 
    rdpShipDate = (sender as RadDatePicker);
    geItem = rdpShipDate.NamingContainer as GridEditableItem;
    NewShipDate = Convert.ToDateTime(rdpShipDate.SelectedDate);
    OldShipDate = Convert.ToDateTime((e as Telerik.Web.UI.Calendar.SelectedDateChangedEventArgs).OldDate);
    fStore = Convert.ToDouble(ExtractValue(geItem,"StoreNumber"));
    iBooth = Convert.ToInt32(ExtractValue(geItem,"BoothNumber"));
    dItemID = Convert.ToDouble(ExtractValue(geItem,"ItemID"));
    iPage = Convert.ToInt32(ExtractValue(geItem,"PageNumber"));
    strOldDel = OldShipDate.ToShortDateString();
    strNewDel = NewShipDate.ToShortDateString();
    wsOrder = new WsOrderSystem();       
    bUpdate = wsOrder.UpdateOrder(fStore,iBooth,iPage,dItemID,strOldDel,strNewDel);
}
 
private string ExtractValue(GridEditableItem geItem,string UniqueName)
{
    TableCell tCell;
    string strValue;
 
    tCell = geItem[UniqueName];
    strValue = (tCell.Controls[0] as TextBox).Text;
    strValue = strValue.Replace("$", "");
    return strValue;
}

I pasted the relevant code - but some of the page controls I left out
0
Elliott
Top achievements
Rank 2
answered on 14 Jul 2011, 01:47 PM
when I replace these 2 columns
<telerik:GridTemplateColumn UniqueName="Cases" HeaderText="" >
    <EditItemTemplate>
        <telerik:RadNumericTextBox ID="rntbQty" Text='<%# Eval("Qty") %>' MinValue='<%# Bind("Qty") %>' OnTextChanged="rntbQty_TextChanged" AutoPostBack="True" Width="30px" runat="server">
            <NumberFormat DecimalDigits="0" />
        </telerik:RadNumericTextBox>
    </EditItemTemplate>
    <HeaderStyle Width="30px" />           
</telerik:GridTemplateColumn>
<telerik:GridBoundColumn UniqueName="Qty" DataField="Qty" HeaderText="Cases" DataFormatString="{0:#####}" DataType="System.Int32" Aggregate="Sum" ReadOnly="True" >
    <HeaderStyle Width="30px" />
</telerik:GridBoundColumn>
with this one column
<telerik:GridTemplateColumn UniqueName="Qty" HeaderText="Cases" Aggregate="Sum" >
     <ItemTemplate>
         <asp:Label ID="lblQty" Text='<%# Bind("Qty") %>' Width="40px" runat="server" />
     </ItemTemplate>
     <EditItemTemplate>
         <telerik:RadNumericTextBox ID="rntbQty" Text='<%# Eval("Qty") %>' MinValue='<%# Bind("Qty") %>' OnTextChanged="rntbQty_TextChanged" AutoPostBack="True" Width="40px" runat="server">
             <NumberFormat DecimalDigits="0" />
         </telerik:RadNumericTextBox>
     </EditItemTemplate>
     <HeaderStyle Width="40px" />
 </telerik:GridTemplateColumn>

the page throws an exception
0
Vasil
Telerik team
answered on 20 Jul 2011, 09:54 AM
Hello Marianne,

In the "Qty" column, you should use Eval, to evaluate the value of Qty field to the MinValue of the rntbQty NumericTextBox.
In the ItemTemplate you should use Eval instead of Bind for populating the Label.
Also you should Bind to the DbValue property instead of the text property if the type in you database is numeric.

Try the declaration below and if the problem still exist please let me know what exactly is the exception.

<telerik:GridTemplateColumn UniqueName="Qty" HeaderText="Cases" Aggregate="Sum">
  <ItemTemplate>
    <asp:Label ID="lblQty" Text='<%# Eval("Qty") %>' Width="40px" runat="server" />
  </ItemTemplate>
  <EditItemTemplate>
    <telerik:RadNumericTextBox ID="rntbQty" DbValue='<%# Bind("Qty") %>' MinValue='<%# Eval("Qty") %>'
      OnTextChanged="rntbQty_TextChanged" AutoPostBack="True" Width="40px" runat="server">
      <NumberFormat DecimalDigits="0" />
    </telerik:RadNumericTextBox>
  </EditItemTemplate>
  <HeaderStyle Width="40px" />
</telerik:GridTemplateColumn>
 
All the best,
Vasil
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Elliott
Top achievements
Rank 2
answered on 20 Jul 2011, 03:03 PM

 

getting exception - doesn't like the aggregate

 

Server Error in '/WebPages' Application.

The expression contains invalid name: '[])'.

 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SyntaxErrorException: The expression contains invalid name: '[])'.

Source Error:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[SyntaxErrorException: The expression contains invalid name: '[])'.]
   System.Data.ExpressionParser.ScanName(Char chEnd, Char esc, String charsToEscape) +259
   System.Data.ExpressionParser.Scan() +903
   System.Data.ExpressionParser.ParseAggregateArgument(FunctionId aggregate) +82
   System.Data.ExpressionParser.Parse() +2716
   System.Data.DataExpression..ctor(DataTable table, String expression, Type type) +201
   System.Data.DataExpression..ctor(DataTable table, String expression) +42
   System.Data.DataTable.Compute(String expression, String filter) +91
   Telerik.Web.UI.GridTemplateColumn.ApplyAggregates(TableCell cell, String footerText) +2004
   Telerik.Web.UI.GridTemplateColumn.cell_DataBinding(Object sender, EventArgs e) +680
   System.Web.UI.Control.OnDataBinding(EventArgs e) +148
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +199
   System.Web.UI.Control.DataBind() +36
   System.Web.UI.Control.DataBindChildren() +260
   System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding) +210
   System.Web.UI.Control.DataBind() +36
   Telerik.Web.UI.GridItem.SetupItem(Boolean dataBind, Object dataItem, GridColumn[] columns, ControlCollection rows) +1001
   Telerik.Web.UI.GridTableView.CreateFooterItem(Boolean useDataSource, GridColumn[] copiedColumnSet, GridTFoot tfoot) +126
   Telerik.Web.UI.GridTableView.CreateControlHierarchy(Boolean useDataSource) +1593
   Telerik.Web.UI.GridTableView.CreateChildControls(IEnumerable dataSource, Boolean useDataSource) +771
   System.Web.UI.WebControls.CompositeDataBoundControl.PerformDataBinding(IEnumerable data) +99
   System.Web.UI.WebControls.DataBoundControl.OnDataSourceViewSelectCallback(IEnumerable data) +174
   System.Web.UI.DataSourceView.Select(DataSourceSelectArguments arguments, DataSourceViewSelectCallback callback) +112
   System.Web.UI.WebControls.DataBoundControl.PerformSelect() +217
   Telerik.Web.UI.GridTableView.PerformSelect() +38
   System.Web.UI.WebControls.BaseDataBoundControl.DataBind() +125
   Telerik.Web.UI.GridTableView.DataBind() +354
   Telerik.Web.UI.RadGrid.DataBind() +165
   Telerik.Web.UI.RadGrid.AutoDataBind(GridRebindReason rebindReason) +3881
   Telerik.Web.UI.RadGrid.OnLoad(EventArgs e) +177
   System.Web.UI.Control.LoadRecursive() +122
   System.Web.UI.Control.LoadRecursive() +244
   System.Web.UI.Control.LoadRecursive() +244
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3416

 


Version Information: Microsoft .NET Framework Version:2.0.50727.3620; ASP.NET Version:2.0.50727.3618

0
Vasil
Telerik team
answered on 22 Jul 2011, 03:08 PM
Hi Marianne,

Set DataField and DataType properties inside the decalration of the column. This should work:
DataField="Qty" DataType="System.Int32"

Best wishes,
Vasil
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Elliott
Top achievements
Rank 2
answered on 25 Jul 2011, 04:14 PM
Vasil - that fixed it
thanks
Tags
Grid
Asked by
Elliott
Top achievements
Rank 2
Answers by
Veli
Telerik team
Elliott
Top achievements
Rank 2
Vasil
Telerik team
Share this question
or