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

Grid inserts without datasource

2 Answers 157 Views
Grid
This is a migrated thread and some comments may be shown as answers.
JedF
Top achievements
Rank 1
JedF asked on 03 Nov 2010, 03:35 PM
Hello

I have a grid that i want to insert new rows into but i dont want the rows committing to the database. This is the top of my grid.
Is this possible?
<telerik:RadGrid runat="server" ID="grdInvoiceLines" AllowPaging="True" AutoGenerateColumns="false"
                GridLines="Both" ShowFooter="true" ShowHeader="true" AllowMultiRowSelection="false" AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" OnItemUpdated="grdInvoiceLines_ItemUpdated"
            OnItemDeleted="grdInvoiceLines_ItemDeleted" OnItemInserted="grdInvoiceLines_ItemInserted" OnDataBound="grdInvoiceLines_DataBound">
                <MasterTableView DataKeyNames="InvoiceLineId" CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true"
                    EditMode="InPlace" AllowAutomaticUpdates="True">

I want to store the inserted values in viewstate. 

Thanks In advance

<telerik:RadGrid runat="server" ID="grdInvoiceLines" AllowPaging="True" AutoGenerateColumns="false"
                GridLines="Both" ShowFooter="true" ShowHeader="true" AllowMultiRowSelection="false" AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" OnItemUpdated="grdInvoiceLines_ItemUpdated"
            OnItemDeleted="grdInvoiceLines_ItemDeleted" OnItemInserted="grdInvoiceLines_ItemInserted" OnDataBound="grdInvoiceLines_DataBound">
                <MasterTableView DataKeyNames="InvoiceLineId" CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true"
                    EditMode="InPlace" AllowAutomaticUpdates="True">
<telerik:RadGrid runat="server" ID="grdInvoiceLines" AllowPaging="True" AutoGenerateColumns="false"
                GridLines="Both" ShowFooter="true" ShowHeader="true" AllowMultiRowSelection="false" AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" OnItemUpdated="grdInvoiceLines_ItemUpdated"
            OnItemDeleted="grdInvoiceLines_ItemDeleted" OnItemInserted="grdInvoiceLines_ItemInserted" OnDataBound="grdInvoiceLines_DataBound">
                <MasterTableView DataKeyNames="InvoiceLineId" CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true"
                    EditMode="InPlace" AllowAutomatic
<im<telerik:RadGrid runat="server" ID="grdInvoiceLines" AllowPaging="True" AutoGenerateColumns="false"
                GridLines="Both" ShowFooter="true" ShowHeader="true" AllowMultiRowSelection="false" AllowAutomaticDeletes="True"
            AllowAutomaticInserts="True" PageSize="10" AllowAutomaticUpdates="True" OnItemUpdated="grdInvoiceLines_ItemUpdated"
            OnItemDeleted="grdInvoiceLines_ItemDeleted" OnItemInserted="grdInvoiceLines_ItemInserted" OnDataBound="grdInvoiceLines_DataBound">
                <MasterTableView DataKeyNames="InvoiceLineId" CommandItemDisplay="Top" ShowHeadersWhenNoRecords="true"
                    EditMode="InPlace" AllowAutomaticUpdates="True">g src="http://www.telerik.com/Images/Forum/codeBlockV2.gif" img="" alt="">
Updates="True">

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 04 Nov 2010, 07:49 AM
Hello,

If you dont want to use DataBase, you can provide data source for RadGrid control probably by using a DataTable or DataSet control. You can insert new rows to DataTable instance and then assign as the DataSource property of the control.

Check out the following Demo for more information on using different data sources.
Grid / Various DataSources

Thanks,
Princy.
0
Marin
Telerik team
answered on 04 Nov 2010, 11:52 AM
Hello JedF,

You can use the InsertCommand event and there you can store the new item wherever you like. Also note that you can store in viewstate only object that are serializable, so generally it is not a good practice to store a lot of data there. Here is how you can retrieve the new values in the InsertCommand event:
protected void RadGrid1_InsertCommand(object sender, GridCommandEventArgs e)
    {
        Hashtable ht = new Hashtable();
        e.Item.OwnerTableView.ExtractValuesFromItem(ht, e.Item as GridEditableItem);
        //ht will contain the newly inserted values
    }

Hope this helps. Let me know if you have any other questions.

Best wishes,
Marin
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
JedF
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Marin
Telerik team
Share this question
or