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

Numeric Value is null on Insert and Update

3 Answers 246 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Bruce
Top achievements
Rank 1
Bruce asked on 25 Mar 2011, 10:39 PM
All,

I am trying to do an insert/update of a numeric value. I have identical code in another control working just fine. All attempts to insert or update result in OriginalAmount being null. I have tried using a bound column and a numeric column with the same failure.

Any and all help is greatly appreciated. I cannot understand how this was working before and now does not, and another control with identical grid and code is fine.

Thanks,
Bruce

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True"
    AllowSorting="True" AutoGenerateColumns="False" GridLines="None" OnInsertCommand="RadGrid1_InsertCommand"
    OnItemCommand="RadGrid1_ItemCommand" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnUpdateCommand="RadGrid1_UpdateCommand" OnItemDataBound="RadGrid1_ItemDataBound"
    OnItemCreated="RadGrid1_ItemCreated" Width="100%">
    <HeaderContextMenu CssClass="GridContextMenu GridContextMenu_Default">
    </HeaderContextMenu>
    <MasterTableView AllowMultiColumnSorting="True" CommandItemDisplay="Top" DataKeyNames="ID,OriginalAmount"
        CommandItemSettings-AddNewRecordText="Add new payment or credit"
        ClientDataKeyNames="ID" Font-Size="Smaller">
        <EditFormSettings>
            <EditColumn FilterControlAltText="Filter EditCommandColumn column">
            </EditColumn>
        </EditFormSettings>
        <PagerStyle Mode="NextPrevNumericAndAdvanced" />
        <CommandItemSettings ExportToPdfText="Export to Pdf"></CommandItemSettings>
        <RowIndicatorColumn FilterControlAltText="Filter RowIndicator column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </RowIndicatorColumn>
        <ExpandCollapseColumn FilterControlAltText="Filter ExpandColumn column">
            <HeaderStyle Width="20px"></HeaderStyle>
        </ExpandCollapseColumn>
        <Columns>
            <telerik:GridEditCommandColumn FilterControlAltText="Filter EditCommandColumn column"
                ButtonType="PushButton">
                <ItemStyle Font-Size="Smaller" Width="10%" />
            </telerik:GridEditCommandColumn>
            <telerik:GridButtonColumn CommandName="Rollback" ConfirmText="Are you sure you want to roll back the application of this payment/credit?"
                ConfirmTitle="Rollback?" FilterControlAltText="Filter Rollback column" Text="Rollback"
                UniqueName="Rollback" ButtonType="PushButton">
            </telerik:GridButtonColumn>
            <telerik:GridButtonColumn CommandName="Apply"
                FilterControlAltText="Filter Apply column" Text="Apply"
                UniqueName="Apply" ButtonType="PushButton">
            </telerik:GridButtonColumn>
            <telerik:GridButtonColumn CommandName="ViewApplication"
                FilterControlAltText="Filter View Application column" Text="View"
                UniqueName="ViewApplication" ButtonType="PushButton">
            </telerik:GridButtonColumn>
            <telerik:GridButtonColumn CommandName="NSF"
                FilterControlAltText="Filter NSF column" Text="NSF"
                UniqueName="NSF" ButtonType="PushButton">
            </telerik:GridButtonColumn>
            <telerik:GridDateTimeColumn DataField="CreditDate" DataType="System.DateTime" FilterControlAltText="Filter CreditDate column"
                HeaderText="Credit Date" UniqueName="CreditDate" DataFormatString="{0:MM/dd/yyyy}">
            </telerik:GridDateTimeColumn>
            <telerik:GridTemplateColumn DataField="ActivityTypeID" FilterControlAltText="Filter ActivityType column"
                HeaderText="Type" UniqueName="ActivityType">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="rcbActivityType" runat="server">
                    </telerik:RadComboBox>
                </EditItemTemplate>
                <ItemTemplate>
                    <asp:Label ID="lblActivityType" runat="server" Text='<%# Eval("ActivityTypeID") %>'></asp:Label>
                </ItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="CreditIdentifier" FilterControlAltText="Filter Check Number column"
                HeaderText="Check Number" MaxLength="500" UniqueName="CreditIdentifier">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="OriginalAmount"
                FilterControlAltText="Filter OriginalAmount column"
                HeaderText="Original Amt." UniqueName="OriginalAmount"
                DataFormatString="{0:C2}">
            </telerik:GridBoundColumn>
 
            <telerik:GridNumericColumn DataField="RemainingAmount" DataType="System.Decimal"
                DecimalDigits="2" FilterControlAltText="Filter RemainingAmount column" HeaderText="Remaining Amt."
                NumericType="Currency" ReadOnly="True" UniqueName="RemainingAmount">
            </telerik:GridNumericColumn>
            <telerik:GridBoundColumn DataField="Notes" FilterControlAltText="Filter Notes column" ColumnEditorID="GridTextBoxColumnEditor1"
                HeaderText="Notes" MaxLength="500" UniqueName="Notes">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="CreatedBy" FilterControlAltText="Filter CreatedBy column"
                HeaderText="Created By" MaxLength="50" ReadOnly="True"
                UniqueName="CreatedBy" Display="False">
            </telerik:GridBoundColumn>
 
 
        </Columns>
        <EditFormSettings>
            <EditColumn UniqueName="EditCommandColumn1" FilterControlAltText="Filter EditCommandColumn column" ButtonType="PushButton">
            </EditColumn>
        </EditFormSettings>
        <PagerStyle Mode="NextPrevNumericAndAdvanced"></PagerStyle>
    </MasterTableView>
    <FilterMenu EnableImageSprites="False">
    </FilterMenu>
</telerik:RadGrid>

protected void RadGrid1_UpdateCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e)
{
    LaundryLogicDAL.ARCredits oARC = new LaundryLogicDAL.ARCredits();
 
    try
    {
        oARC.es.Connection.Name = "NAS";
        oARC.es.Connection.SqlAccessType = esSqlAccessType.DynamicSQL;
 
        GridEditableItem editedItem = e.Item as GridEditableItem;
        GridEditManager editMan = editedItem.EditManager;
 
        int iID = (int)editedItem.OwnerTableView.DataKeyValues[editedItem.ItemIndex]["ID"];
 
        DateTime dteCreditDate = DateTime.Parse((editMan.GetColumnEditor("CreditDate") as GridDateTimeColumnEditor).Text);
        int iActivityTypeID = Convert.ToInt16((editedItem["ActivityType"].FindControl("rcbActivityType") as RadComboBox).SelectedValue);
        decimal dOriginalAmount = CurrencyToDecimal((editMan.GetColumnEditor("OriginalAmount") as GridTextBoxColumnEditor).Text);
        string sNotes = (editMan.GetColumnEditor("Notes") as GridTextBoxColumnEditor).Text;
        string sCreditIdentifier = (editMan.GetColumnEditor("CreditIdentifier") as GridTextBoxColumnEditor).Text;
 
        if (oARC.LoadByPrimaryKey(iID))
        {
            oARC.CreditDate = dteCreditDate;
            oARC.ActivityTypeID = iActivityTypeID;
            oARC.CreditIdentifier = sCreditIdentifier;
            oARC.OriginalAmount = dOriginalAmount;
            oARC.Notes = sNotes;
            oARC.Save();
        }
    }
    catch (Exception ex)
    {
        DotNetNuke.Services.Exceptions.Exceptions.ProcessModuleLoadException(this, ex);
    }
    finally
    {
        oARC = null;
    }

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 30 Mar 2011, 01:38 PM
Hello Bruce,

Can you please try the following code and see whether it helps.

C#:
protected void RadGrid1_UpdateCommand(object sender, GridCommandEventArgs e)
   {
       GridEditableItem editedItem = e.Item as GridEditableItem;
       GridEditManager editMan = editedItem.EditManager;
       Hashtable newValues = new Hashtable();
       e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
       string id = newValues["ActivityType"].ToString();
    }

-Shinu.
0
Bruce
Top achievements
Rank 1
answered on 03 Apr 2011, 01:22 PM
Hi Shinu,

Thanks for your reply, and sorry for the delay. I have been under a tight deadline to get this project complete.

Your suggestion was the first thing I tried as it is the way I prefer to get data from the grid. Unfortunately, the hashtable doesn't even include a record for the field if the column is a GridNumericColumn. When I inspect oHT, there is no oHT[columnname] if the column is a GridNumericColumn. The only way I have found to access the data successfully is to change it to a template column. I have had to do this in all cases in my interface.

I really thought the GridNumericColumn was supposed to  behave like a GridBoundColumn, but it doesn't appear to be the case.

Thanks,
Bruce
0
Martin
Telerik team
answered on 06 Apr 2011, 02:45 PM
Hello Bruce Parr,

Please note that when you have a ReadOnly column, and want to extract its value, you should set its ForceExtractValue property (default value is "None"). The following help topic provides more details:

Data editing support

I hope this helps.

Greetings,
Martin
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
Tags
Grid
Asked by
Bruce
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Bruce
Top achievements
Rank 1
Martin
Telerik team
Share this question
or