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

Batch Editing and Adding a New Record

1 Answer 428 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
Kyle
Top achievements
Rank 1
Kyle asked on 05 Jan 2018, 10:08 PM

I have a RadGrid set for Batch Editing and I have half of the columns as Read Only and the ones that are editable are all check boxes (Months of the Year). I want to be able to insert a new record and be able to insert some information in the columns that are Read Only during the edit.  I've tried a few different things and it seems like its all or nothing.  If I have the column set as Read Only then even when I click to insert a new record it won't allow anything.  And if I don't have the column set to Read Only, even though I have my RadComboBox in the <InsertItemTemplate> section of GridTemplateColumn, it allows me to edit existing rows.

What would be the best way to be able to accomplish this?

 

Any help is appreciated..

 

1 Answer, 1 is accepted

Sort by
0
Marin Bratanov
Telerik team
answered on 10 Jan 2018, 02:10 PM

Hello Kyle,

You can:

  1. use GridTemplateColumn instances
  2. keep an empty EditItemTemplate
  3. provide the insertion controls you want in the InsertItemTemplate (tip: use RadDropDownList instances because RadComboBox is not supported with the batch editing)

Here is a basic example:

<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource" AutoGenerateColumns="false">
    <MasterTableView EditMode="Batch" CommandItemDisplay="Top">
        <BatchEditingSettings EditType="Row" />
        <Columns>
            <telerik:GridTemplateColumn DataField="id" UniqueName="idColumn">
                <ItemTemplate>
                      <%# Eval("id") %>
                </ItemTemplate>
                <EditItemTemplate>
                </EditItemTemplate>
                <InsertItemTemplate>
                    <telerik:RadDropDownList runat="server" ID="rddl1">
                        <Items>
                            <telerik:DropDownListItem Text="first" Value="1" />
                            <telerik:DropDownListItem Text="second" Value="2" />
                            <telerik:DropDownListItem Text="third" Value="3" />
                            <telerik:DropDownListItem Text="fourth" Value="4" />
                        </Items>
                    </telerik:RadDropDownList>
                </InsertItemTemplate>
            </telerik:GridTemplateColumn>
            <telerik:GridBoundColumn DataField="firstField" UniqueName="textColumn"></telerik:GridBoundColumn>
             <telerik:GridCheckBoxColumn DataField="moreData" HeaderStyle-Width="80px" HeaderText="checkboxes" UniqueName="Discontinued">
            </telerik:GridCheckBoxColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>
protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    (sender as RadGrid).DataSource = GetDummyData();
}
 
    protected DataTable GetDummyData()
{
    DataTable tbl = new DataTable();
    tbl.Columns.Add(new DataColumn("id", typeof(decimal)));
    tbl.Columns.Add(new DataColumn("firstField", typeof(string)));
    tbl.Columns.Add(new DataColumn("moreData", typeof(bool)));
    tbl.Columns.Add(new DataColumn("someColumn", typeof(string)));
    tbl.Rows.Add(new object[] { 1, "one", false, "firstRecord4" });
    tbl.Rows.Add(new object[] { 2, "two", true, "secondRecord4" });
    tbl.Rows.Add(new object[] { 3, "three", true, "thirdRecord4" });
    tbl.Rows.Add(new object[] { 4, "four", false, "-fourthRecord4" });
 
    return tbl;
}
 

Regards,

Marin Bratanov
Progress Telerik
Try our brand new, jQuery-free Angular components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Dhaval
Top achievements
Rank 1
commented on 09 May 2023, 03:03 PM

Hi Marin,

I have the same design which you have mentioned in the last reply, the only difference is that I want to bind the RadDropDownList which is in the InsertItemTemplate dynamically before the AddNewButton shows a new blank Row in the Parent grid.

Can you please help on ASAP basis as I am stuck due to this..?

Thanks & Regards,

Dhaval Doshi.

Doncho
Telerik team
commented on 12 May 2023, 10:58 AM

Hi Dhaval,

In case you want to populate the items in the DropDownList by providing a DataSource to the Control you can use its OnLoad event to set the DataSource and call its DataBind() method:

protected void rddl1_Load(object sender, EventArgs e)
{
    var ddl = sender as RadDropDownList;
    //set sample data source to the DropDownList
    ddl.DataSource = Enumerable.Range(1, 5).Select(x => new { ShipCountry = "Country " + x });
    ddl.DataBind();
}

Let me share some information about the specifics of using Template columns in Batch edit mode that should be considered:

The BatchEdit is a Client-Side (JavaScript-based) functionality of the Grid, therefore, interaction with the Grid must be done on the Client-Side. Normally using TemplateColumns is not recommended when using BatchEditing but it can be used for simple Templates. Such scenarios however need manual handling of the editing.

The following article describes the main aspects of Batch Editing: RadGrid Batch Editing Templates and Specifics.
The specifics when using templates in Batch editing are explained in the Working With Templates article.
In this case, you should use the Client-Side APIs of both the Grid and the DropDownList to set the values of the cell and editor. The following client-side events can be used for this purpose:

You can find sample implementation using these events in the Working With Templates article linked above. 

We also have a couple of knowledge base articles showcasing the usage of templates in Batch edit mode that you may use as additional reference:

I hope this information will prove helpful.

Tags
General Discussions
Asked by
Kyle
Top achievements
Rank 1
Answers by
Marin Bratanov
Telerik team
Share this question
or