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

OnclientSelectedIndexChanged event firing

1 Answer 316 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Amrutha
Top achievements
Rank 1
Amrutha asked on 31 Mar 2014, 03:36 AM
Hi,

My requirement is to auto populate the textboxes(bound columns) in the insert form on selecting items from a radcombobox which is in the same insert form. My RadGrid is using Batch edit mode. I tried to attach the OnClientSelectedIndexChanged event for the RadCombobox. But after selecting the item and auto populating the TextBoxes(bound columns), the textboxes wont appear, it looks like labels.. The major issue is the OnClientSelectedIndexChanged is firing on the save button click. Please provide a solution for this.

ASPX:
01.<telerik:RadGrid ID="ad" runat="server" OnNeedDataSource="ad_NeedDataSource" AutoGenerateColumns="false">
02.    <MasterTableView EditMode="Batch" CommandItemDisplay="Top">
03.        <BatchEditingSettings EditType="Row" OpenEditingEvent="Click" />
04.        <Columns>
05.            <telerik:GridBoundColumn DataField="testProperty" UniqueName="testProperty" HeaderText="testProperty">
06.            </telerik:GridBoundColumn>
07.            <telerik:GridBoundColumn DataField="test" UniqueName="test" HeaderText="test">
08.            </telerik:GridBoundColumn>
09.            <telerik:GridBoundColumn DataField="description" UniqueName="description" HeaderText="description">
10.            </telerik:GridBoundColumn>
11.            <telerik:GridBoundColumn DataField="code" UniqueName="code" HeaderText="code">
12.            </telerik:GridBoundColumn>
13.            <telerik:GridTemplateColumn HeaderStyle-Width="300px" HeaderText="ShipCountry" UniqueName="ShipCountry"
14.                DataField="ShipCountry">
15.                <ItemTemplate>
16.                    <asp:Label ID="lb" runat="server" Text="jklm"></asp:Label>
17.                </ItemTemplate>
18.                <EditItemTemplate>
19.                    <telerik:RadComboBox runat="server" Skin="WebBlue" ID="RadComboBox1" Height="200px"
20.                        Width="270px" DropDownWidth="800px" OnClientSelectedIndexChanged="OnClientSelectedIndexChanged"
21.                        ShowMoreResultsBox="true" EnableVirtualScrolling="true" ChangeTextOnKeyBoardNavigation="true">
22.                        <Items>
23.                            <telerik:RadComboBoxItem Text="gh1" Value="sdf1" />
24.                            <telerik:RadComboBoxItem Text="gh2" Value="sdf2" />
25.                            <telerik:RadComboBoxItem Text="gh3" Value="sdf34" />
26.                        </Items>
27.                    </telerik:RadComboBox>
28.                </EditItemTemplate>
29.            </telerik:GridTemplateColumn>
30.        </Columns>
31.    </MasterTableView>
32.</telerik:RadGrid>

Js:
1.<script type="text/javascript">
2.    function OnClientSelectedIndexChanged(sender, args) {
3.        alert("fired!!!!!!!!!");
4.    }
5.</script>

Thanks

1 Answer, 1 is accepted

Sort by
0
Angel Petrov
Telerik team
answered on 02 Apr 2014, 02:25 PM
Hi Amrutha,

The first issue described(more precisely the disappearing textboxes) may be caused by a JavaScript error on the page. Could you ensure that such is not present on the page?

As for the firing of the OnClientSelectedIndexChanged event I have to say that your observation are correct. The reason for this behavior is that our internal logic triggers the event when a cell is being closed for edit. If you do not want to execute the logic in the OnClientSelectedIndexChanged event handler when the save button is clicked you can do the following:
  1. Subscribe to the OnBatchEditClosing and OnBatchEditClosed events.
  2. In the OnBatchEditClosing event handler raise a flag which to indicate that the cell is closed for edit.
  3. In the OnClientSelectedIndexChanged check the value of the flag and execute the logic if needed.
  4. In the OnBatchEditClosed event handler restore the flag state.

In the code snippets below you can observe a possible realization of the above suggested approach. In addition the code also illustrates how one can set the value of the GridBoundColumn editor in the OnClientSelectedIndexChanged  event.

ASPX:

<ClientSettings>
               <ClientEvents OnBatchEditClosing="OnBatchEditClosing" OnBatchEditClosed="OnBatchEditClosed" />
           </ClientSettings>

JavaScript:
var shouldExecuteLogic=true;
        function OnBatchEditClosing(sender, args) {
            if (args.get_columnUniqueName() === "ShipCountry") {
                shouldExecuteLogic = false;
            }
        }
        function OnBatchEditClosed(sender, args) {
            if (args.get_columnUniqueName() === "ShipCountry") {
                shouldExecuteLogic = true;
            }
        }
        function OnClientSelectedIndexChanged(sender, args) {
            if (shouldExecuteLogic) {
                var row = Telerik.Web.UI.Grid.GetFirstParentByTagName(sender.get_element(), "tr");
                $telerik.findElement(row, "testProperty").getElementsByTagName("input")[0].value = "Value";
            }
        }

Regards,
Angel Petrov
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Amrutha
Top achievements
Rank 1
Answers by
Angel Petrov
Telerik team
Share this question
or