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

Can't get updated value from Grid

5 Answers 164 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ali
Top achievements
Rank 1
Ali asked on 23 Apr 2013, 10:27 AM
Hi, 

I'm having an issue with getting the updated value from a radgrid table. 

I've tried:

        GridEditableItem editedItem = e.Item as GridEditableItem;
        Hashtable newValues = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);

But newValues hashtable still contains the old value. 

My radgrid table updates on ClientEvent using 

            function RowClick(sender, eventArgs) {
                if (editedRow) {
                    if (hasChanges) {
                        hasChanges = false;
                        if (confirm("Are you sure you want to update this entry?")) {
                            $find("<%= LoadingRadGrid.ClientID %>").get_masterTableView().updateItem(editedRow);
                        }
                    } else {
/////
                    }
                }
            }

Here is my RadGrid:
-----------------------------------------------------------------------------------------------------------------------------------------------------------
            <telerik:RadGrid runat="server" ID="LoadingRadGrid" ShowStatusBar="true" AllowAutomaticUpdates="false"
                OnItemDataBound="LoadingRadGrid_OnDataBinding" OnUpdateCommand="LoadingRadGrid_OnUpdateItem">
                <MasterTableView DataKeyNames="Loading_ID" AutoGenerateColumns="false" EditMode="InPlace"
                    Caption="<b>Load</b>" ShowHeadersWhenNoRecords="true">
                    <Columns>
                        <telerik:GridBoundColumn HeaderText="Comp Index" UniqueName="CompartmentNo" DataField="CompartmentIndex"
                            ReadOnly="true">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="Prod Code" DataField="PlannedProductName"
                            UniqueName="PlannedProductName">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lbl_ProdCode"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="ddl_ProdCodeEditMode">
                                </telerik:RadComboBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                        <telerik:GridBoundColumn HeaderText="Qty" UniqueName="Qty" DataField="PlannedQuantity">
                        </telerik:GridBoundColumn>
                        <telerik:GridTemplateColumn HeaderText="Unit">
                            <ItemTemplate>
                                <asp:Label runat="server" ID="lbl_Unit"></asp:Label>
                            </ItemTemplate>
                            <EditItemTemplate>
                                <telerik:RadComboBox runat="server" ID="ddl_UnitEditMode">
                                </telerik:RadComboBox>
                            </EditItemTemplate>
                        </telerik:GridTemplateColumn>
                    </Columns>
                </MasterTableView>
                <ClientSettings>
                    <Selecting AllowRowSelect="true" />
                    <ClientEvents 
                            OnRowClick="RowClick" 
                            OnRowDblClick="RowDblClick"
                            OnCommand="GridCommand"
                            OnGridCreated="GridCreated"/>
                </ClientSettings>
            </telerik:RadGrid>
-----------------------------------------------------------------------------------------------------------------------------------------------------------

Any suggestions would be much appreciated as I'm working on a tight schedule. 
Also what is the best way of retrieving the changes value of the CustomControl (Combo box).



Many thanks.

5 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 23 Apr 2013, 10:39 AM
Hi,

You can retrieve the combobox value as shown below.
c#:
void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
       GridEditableItem item = (GridEditableItem)e.Item;
       RadComboBox combo = (RadComboBox)item.FindControl("RadComboBox1");
       string value = combo.SelectedItem.Text;
}

Thanks,
Shinu
0
Ali
Top achievements
Rank 1
answered on 23 Apr 2013, 12:25 PM
Thanks you very much Shinu.

Any idea as to why I'm not getting the updated value of the GridBoundColumn and still getting the old value?
0
Shinu
Top achievements
Rank 2
answered on 24 Apr 2013, 04:39 AM
Hi,

ExtractValuesFromItem will return the updated values. As an alternative you can try the following code.
c#:
void RadGrid2_UpdateCommand(object sender, GridCommandEventArgs e)
{
        GridEditableItem item = (GridEditableItem)e.Item;
        TextBox txt = (TextBox)item["Uniquename"].Controls[0];
        string value = txt.Text;
}

Thanks,
Shinu
0
Ali
Top achievements
Rank 1
answered on 29 Apr 2013, 11:53 AM
Hi,

thank you very much for the response. But no matter what I try I'm constantly getting the old value.

Dead lines are fast approaching and this is one of the last things I can't get working. Any help would be greatly appreciated.

<div id="LoadingRadGrid_Holder">
    <telerik:RadGrid
            runat="server"
            ID="LoadingRadGrid"
            ShowStatusBar="true"
            AllowAutomaticUpdates="false"
            OnItemDataBound="LoadingRadGrid_OnDataBound"
            OnUpdateCommand="LoadingRadGrid_OnUpdateItem">
        <MasterTableView DataKeyNames="Loading_ID"
                         AutoGenerateColumns="false"
                         Caption="<span class='GridTableCaption'> Load </span>"
                         ShowHeadersWhenNoRecords="true">
            <Columns>
                <telerik:GridBoundColumn HeaderStyle-Width="16%" ItemStyle-CssClass="maxWidth" HeaderText="Comp Index" UniqueName="CompartmentNo" DataField="CompartmentIndex"
                    ReadOnly="true">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderStyle-Width="36%" ItemStyle-CssClass="maxWidth" HeaderText="Prod Code" DataField="PlannedProductName"
                    UniqueName="PlannedProductName">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lbl_ProdCode"></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox runat="server" ID="ddl_ProdCodeEditMode">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
                <telerik:GridBoundColumn HeaderStyle-Width="36%" ItemStyle-CssClass="maxWidth" HeaderText="Qty" UniqueName="Qty" DataField="PlannedQuantity">
                </telerik:GridBoundColumn>
                <telerik:GridTemplateColumn HeaderText="Unit" HeaderStyle-Width="8%" ItemStyle-CssClass="maxWidth">
                    <ItemTemplate>
                        <asp:Label runat="server" ID="lbl_Unit"></asp:Label>
                    </ItemTemplate>
                    <EditItemTemplate>
                        <telerik:RadComboBox Width="100%" runat="server" ID="ddl_UnitEditMode">
                        </telerik:RadComboBox>
                    </EditItemTemplate>
                </telerik:GridTemplateColumn>
            </Columns>
            <EditFormSettings CaptionFormatString="Edit Loading detail for Loading ID {0}" CaptionDataField="Loading_ID">
                <FormTableItemStyle Wrap="False" Width="100%"></FormTableItemStyle>
                <FormCaptionStyle CssClass="EditFormHeader"></FormCaptionStyle>
                <FormMainTableStyle GridLines="Horizontal" CellSpacing="0" CellPadding="3" Width="100%">
                </FormMainTableStyle>
                <FormTableStyle GridLines="None" CellSpacing="0" CellPadding="2" CssClass="module"
                    Height="110px" Width="100%"></FormTableStyle>
                <FormTableAlternatingItemStyle Wrap="False"></FormTableAlternatingItemStyle>
                <FormStyle Width="100%"></FormStyle>
                <EditColumn ButtonType="ImageButton" InsertText="Insert Order" UpdateText="Update record"
                    UniqueName="EditCommandColumn1" CancelText="Cancel edit">
                </EditColumn>
                <FormTableButtonRowStyle HorizontalAlign="Right" CssClass="EditFormButtonRow"></FormTableButtonRowStyle>
            </EditFormSettings>
        </MasterTableView>
        <ClientSettings>
            <Selecting AllowRowSelect="true" />
            <ClientEvents
                    OnRowClick="RowClick"
                    OnRowDblClick="RowDblClick"
                    OnCommand="GridCommand"
                    OnGridCreated="GridCreated"/>
        </ClientSettings>
    </telerik:RadGrid>
function RowDblClick(sender, eventArgs) {
    var argId = sender.ClientID;
    if (argId == "<%=LoadingRadGrid.ClientID%>") {
        editedRowLoading = eventArgs.get_itemIndexHierarchical();
        $find(argId).get_masterTableView().editItem(editedRowLoading);
    } else if (argId == "<%=DischargeRadGrid.ClientID%>") {
        editedRowDischarge = eventArgs.get_itemIndexHierarchical();
        $find(argId).get_masterTableView().editItem(editedRowDischarge);
    }
 
}

protected void LoadingRadGrid_OnDataBound(object sender, GridItemEventArgs e)
{
    LoadingDetailExtraEntity currentInst = null;
    Boolean edited = false;
    Label label = new Label();
    if (e.Item is GridEditableItem)
    {
        if (!e.Item.IsInEditMode && (e.Item.GetType() == typeof(GridDataItem)))
        {
            GridEditableItem editItem = e.Item as GridEditableItem;
            label = (System.Web.UI.WebControls.Label)editItem.FindControl("lbl_ProdCode");
            currentInst = (LoadingDetailExtraEntity)editItem.DataItem;
            label.Text = currentInst.PlannedProductName;
        }
        else
        {
            GridEditableItem editItem = e.Item as GridEditableItem;
            RadComboBox dropdown = (RadComboBox)editItem.FindControl("ddl_ProdCodeEditMode");
            if (dropdown != null)
            {
                productList = productManager.GetProductList();
                Dictionary<string, string> productDataSource = new Dictionary<string, string>();
                foreach (ProductEntity p in productList)
                {
                    productDataSource.Add(p.MaterialName, p.MaterialName);
                }
                dropdown.DataSource = productDataSource;
                dropdown.DataValueField = "value";
                dropdown.DataTextField = "key";
                dropdown.DataBind();
                currentInst = (LoadingDetailExtraEntity)editItem.DataItem;
                dropdown.SelectedIndex = dropdown.Items.FindItemByValue(currentInst.PlannedProductName).Index;
            }
        }
        if (!edited)
        {
            if (currentInst != null)
            {
                lbl_LoadingStart.Text = currentInst.TimeOfEntry.ToShortDateString();
                lbl_LoadingEnd.Text = currentInst.TimeOfExit.ToShortDateString();
                lbl_TerminalId.Text = currentInst.Plant_ID.ToString();
                lbl_TerminalName.Text = currentInst.TerminalName;
                edited = true;
            }
        }
    }
 
}
protected void LoadingRadGrid_OnUpdateItem(object sender, GridCommandEventArgs e)
{
    GridEditableItem editedItem = e.Item as GridEditableItem;
    TextBox txt = (TextBox)editedItem["Qty"].Controls[0];
    string value = txt.Text;
    //GridEditableItem editedItem = e.Item as GridEditableItem;
    //Prepare new dictionary object
    //Hashtable newValues = new Hashtable();
    //e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
0
Ali
Top achievements
Rank 1
answered on 29 Apr 2013, 12:25 PM
Problem Solved! 

I was being silly and getting the data at the wrong point, so the data rebinded data from db. 

thanks for the responses
Tags
Grid
Asked by
Ali
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ali
Top achievements
Rank 1
Share this question
or