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

[Solved] Problems adding new Record

1 Answer 127 Views
Grid
This is a migrated thread and some comments may be shown as answers.
masterK
Top achievements
Rank 1
masterK asked on 04 Aug 2009, 07:35 AM
I have a grid that I am databinding to an in memory object. When i add a record I enter the new record details and press insert, the backend event seems to be getting fired but all the values of the columns are null.

 <telerik:RadGrid ID="RadGrid1" GridLines="None" runat="server"
             AllowAutomaticUpdates="True" AllowPaging="True"
            AutoGenerateColumns="False" OnItemCommand="RadGrid1_ItemInsert" OnInsertCommand="RadGrid1_ItemInsert" OnItemUpdated="RadGrid1_Itemupdate" OnEditCommand="RadGrid1_ItemUpdated"
            OnDeleteCommand="RadGrid1_ItemDeleted" OnItemInserted="RadGrid1_ItemInserted" OnDataBound="RadGrid1_DataBound" AutoGenerateEditColumn="True">
                <MasterTableView CommandItemDisplay="Bottom" AllowAutomaticInserts="True" DataKeyNames="ID">                    
                    <Columns>       
                        <telerik:GridBoundColumn DataField="ID" HeaderText="ID" SortExpression="ID"
                            UniqueName="ID">
                        </telerik:GridBoundColumn>                       
                        <telerik:GridBoundColumn DataField="Name" HeaderText="Name" SortExpression="Name"
                            UniqueName="Name">
                        </telerik:GridBoundColumn>                       
                        <telerik:GridBoundColumn DataField="DisplayName" HeaderText="DisplayName" SortExpression="DisplayName"
                            UniqueName="DisplayName">
                        </telerik:GridBoundColumn>
                        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName= "DeleteColumn" />
                    </Columns>                     
                </MasterTableView>
            </telerik:RadGrid>            

Code behind:
protected void RadGrid1_ItemInsert(object source, Telerik.Web.UI.GridCommandEventArgs e)
        {
            if (e.CommandName == RadGrid.InitInsertCommandName) //"Add new" button clicked
            {
                RadGrid1.DataSource = SessionHelper.XMLLayoutKey.layoutField;
                RadGrid1.DataBind();
            }
            else if (e.CommandName == RadGrid.PerformInsertCommandName)  
            {
                GridEditFormInsertItem editedItem = (GridEditFormInsertItem)e.Item;
                string strCategoryName = editedItem["Name"].Text;  
            }
        }

The column named "Name" is found yet it's value is always empty even though it has a value.

Any ideas?

1 Answer, 1 is accepted

Sort by
0
masterK
Top achievements
Rank 1
answered on 04 Aug 2009, 08:34 AM
Actually found the solution, put the following in the code behind:
GridEditableItem editedItem = e.Item as GridEditableItem;
                Hashtable newValues = new Hashtable();
                e.Item.OwnerTableView.ExtractValuesFromItem(newValues, editedItem);
Tags
Grid
Asked by
masterK
Top achievements
Rank 1
Answers by
masterK
Top achievements
Rank 1
Share this question
or