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

Batch Edit Mode handle ItemBound and ItemCommand event

3 Answers 312 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Sunit
Top achievements
Rank 1
Sunit asked on 25 Mar 2014, 11:59 AM
I have a RadGrid in batch edit mode.
I have  a EditTemplate column which has a dropdown. On selection change of the dropdown I want to show\hide column is the next adjacent column the column that I can show can be Text box or Listbox  + Texbox + button. 
Also I need to handle the button click of this button in the edit mode.

For show\hide of control based of dropdown value selected I expect the ItemBoundEvent to fire and 
to handle the button click event I expect ItemCommandEvent event to fire. 

But it seems that in Batch Edit mode neither of the above two events gets fired. So I'm stuck on how to implement this functionality.

How do I achieve this functionality in this case? 
Thank you

3 Answers, 1 is accepted

Sort by
0
Danail Vasilev
Telerik team
answered on 27 Mar 2014, 03:47 PM
Hello Sunit,

Please find by comments and suggestions below:

1)Toggle visibility of GridTemplateColumn's adjacent column - You can handle the RadDropDownList's client-side OnClientSelectedIndexChanged event where you can obtain the adjacent column and toggle its visibility. For example:
JavaScript:
function ToggleButtonColumnVisibility(sender, args) {
    var selIndex = args.get_index();
    var grid = $find("<%=RadGrid1.ClientID%>");
    if (selIndex == 1) {
        grid.get_masterTableView().hideColumn(Telerik.Web.UI.Grid.GetFirstParentByTagName(sender.get_element(), "td").cellIndex + 1);
    }
    else {
        grid.get_masterTableView().showColumn(Telerik.Web.UI.Grid.GetFirstParentByTagName(sender.get_element(), "td").cellIndex + 1);
    }
}

ASPX:
<telerik:GridTemplateColumn UniqueName="DropDownColumn" HeaderText="DropDownColumn">
    <ItemTemplate>
        Toggle Column Visibility <%#Eval("ID") %>
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadDropDownList ID="RadDropDownList1" runat="server" OnClientSelectedIndexChanged="ToggleButtonColumnVisibility">
            <Items>
                <telerik:DropDownListItem Text="true" />
                <telerik:DropDownListItem Text="false" Selected="true" />
            </Items>
        </telerik:RadDropDownList>
    </EditItemTemplate>
</telerik:GridTemplateColumn>

2) Handle the button's click in edit mode - You can handle the client-side and server-side events of the button in edit mode in the same ways as with a simple button's declaration. For example:
JavaScript:
function OnClientClicking(sender, args) {
    args.set_cancel(!window.confirm('Are you sure you want to postback?'));
}

ASPX:
<telerik:GridTemplateColumn Display="false" UniqueName="ButtonColumn" HeaderText="ButtonColumn">
    <ItemTemplate>
        '<%# Eval("ButtonColumn") %>'
    </ItemTemplate>
    <EditItemTemplate>
        <telerik:RadButton ID="RadButton1" runat="server" OnClick="Button1_Click" Text='Click' OnClientClicking="OnClientClicking" />
    </EditItemTemplate>
</telerik:GridTemplateColumn>
C#:
protected void Button1_Click(object sender, EventArgs e)
{
    Label1.Text = "server click triggered on" + DateTime.Now;
}

3) ItemDataBound and ItemCommand events triggering in Batch Edit mode - When you open a cell for editing in Batch Edit mode it is expected for the server-side events like ItemDataBound and ItemCommand not to be triggered because Batch Edit is a client-side oriented mode and the entire editing is handled on the client-side. If you want, however, to feed a particular control with a data source on the client you can subscribe to the OnBatchEditCellValueChanged event, for example. Note, however, that if the RadGrid's changes from the BatchEdit are not saved and a postback is performed the changes will be lost.

You can find a full runnable VS example in with the above approaches in the attached archive.

Regards,
Danail Vasilev
Telerik
 

Build cross-platform mobile apps using Visual Studio and .NET. Register for the online webinar on 03/27/2014, 11:00AM US ET.. Seats are limited.

 
0
shashi
Top achievements
Rank 1
answered on 12 Jan 2016, 08:05 PM
I have a label and in edit field a dropdown list. I have to show the value of label in the dropdown as the first list value. I am trying to attach a jquery function to the dropdown list on batchedit command .but the batch edit command is not firing .please help me with this.
0
Danail Vasilev
Telerik team
answered on 13 Jan 2016, 12:11 PM
Hello Shashi,

Which batchedit command/event is not fired? I have tried attaching to the client-side OnBatchEditOpened event and everything works properly on my side. You can find below the modification to the provided example from my previous answer:
JavaScript:
function OnBatchEditOpened(sender, args) {
    alert(1);
}
ASPX:
<telerik:RadGrid runat="server" ID="RadGrid1" OnNeedDataSource="RadGrid1_NeedDataSource">
            <ClientSettings>
                <ClientEvents OnBatchEditOpened="OnBatchEditOpened" />
            </ClientSettings>
...


Regards,
Danail Vasilev
Telerik
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 Feedback Portal and vote to affect the priority of the items
Tags
Grid
Asked by
Sunit
Top achievements
Rank 1
Answers by
Danail Vasilev
Telerik team
shashi
Top achievements
Rank 1
Share this question
or