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

RadGridEditTemplate

5 Answers 57 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Farjana
Top achievements
Rank 1
Farjana asked on 18 Nov 2013, 01:29 PM
Hi,
I have an aspx page with some text boxes, buttons and a radgrid with edit template column. when i click on "add new row" i get some editable boxes in grid to add value. it is having "insert" and "cancel" buttons next to it. i dont want these buttons. instead i have a "save" button in the page. I want all the values from textboxes and grid needs to be saved when clicking on save button.

I dont want to seperately click on "insert" button in the grid to be clicked.

5 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 19 Nov 2013, 05:47 AM
Hi Farjana,

Please try the following code snippet to insert on Save button, which is outside the RadGrid.

APSX:
<telerik:RadGrid ID="RadGrid1" runat="server" OnNeedDataSource="RadGrid1_NeedDataSource"
    OnItemDataBound="RadGrid1_ItemDataBound">
    <MasterTableView DataKeyNames="OrderID" CommandItemDisplay="Top">
        <Columns>
            <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />         
            <telerik:GridTemplateColumn HeaderText="ShipCountry">
                <EditItemTemplate>
                    <telerik:RadComboBox ID="RadComboBox1" runat="server" DataSourceID="SqlDataSource1"
                        DataTextField="ShipCountry" DataValueField="ShipCountry">
                    </telerik:RadComboBox>
                </EditItemTemplate>
            </telerik:GridTemplateColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
<asp:Button ID="ButtonSave" runat="server" Text="Save" OnClick="ButtonSave_Click" />

C#:
protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)
{
    if (e.Item is GridEditFormInsertItem && e.Item.OwnerTableView.IsItemInserted)
    {
        GridEditFormInsertItem insertitem=(GridEditFormInsertItem)e.Item;
        //Hide Insert Button
        LinkButton insertlink = (LinkButton)insertitem.FindControl("PerformInsertButton");
        insertlink.Visible = false;
        //Hide Cancel Button
        LinkButton cancellink = (LinkButton)insertitem.FindControl("CancelButton");
        cancellink.Visible = false;
    }
}
protected void ButtonSave_Click(object sender, EventArgs e)
    if (RadGrid1.MasterTableView.IsItemInserted)
    {
        GridEditableItem insert = (GridEditableItem)RadGrid1.MasterTableView.GetInsertItem();
        TextBox txt1 = (TextBox)insert["OrderID"].Controls[0];//Access BoundColumn
        string id = txt1.Text;
        RadComboBox combo = (RadComboBox)insert.FindControl("RadComboBox1"); //Access Template Column
        string value = combo.SelectedValue;
        // Code to Insert to DB
        RadGrid1.MasterTableView.IsItemInserted = false;// Close Insert Form
        RadGrid1.Rebind();
    }
}

Thanks,
Princy
0
Farjana
Top achievements
Rank 1
answered on 29 Nov 2013, 06:29 AM
Hi Princy,

Thanks for your input. Am able to disable the "insert/cancel" button on "Add new record" command. But i would like to insert multiple rows at a time and finally click on save button to insert all records in one shot. Can you tell me how to achieve this?


Thanks,
Farjana
0
Princy
Top achievements
Rank 2
answered on 29 Nov 2013, 06:45 AM
Hi Farjana,

Unfortunately, RadGrid does not support multiple insert forms visible simultaneously. One suggestion to achieve multiple insert is by using an external form with multiple fields for insert. Thus when pressing a button from that external form you can extract the values from the input fields, insert the new records in the grid source and rebind the control to reflect the changes.

Thanks,
Princy.
0
Farjana
Top achievements
Rank 1
answered on 29 Nov 2013, 06:49 AM
Hi Princy,

Thanks for your suggestion. Is there any demo to achieve the external form functionality?

Thanks,
Farjana
0
Princy
Top achievements
Rank 2
answered on 02 Dec 2013, 05:15 AM
Hi Farjana,

I suggest that you use a similar approach to the one in the Insert with Tooltip online example to implement the desired functionality.

Thanks,
Princy

Tags
Grid
Asked by
Farjana
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Farjana
Top achievements
Rank 1
Share this question
or