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

RadGrid Selection: MultiCell GetSelected

3 Answers 48 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 29 Jul 2013, 02:42 PM
Hi,

I'm trying to build a grid using the multicell selection but i haven't been able to find how i'm supposed to get the selected cells after they have been selected? using get_selecteditems does not contain any objects for the selected cells. Am i missing something?

Any help would be great as i can't find an example in the Telerik knowledge base.

Thanks,
JC

3 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 1
answered on 30 Jul 2013, 07:00 AM
Hi John,

I guess you want to get the selected cell value.Please try the below code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server"  " AllowPaging="true">
    <MasterTableView >
        <Columns>
           . . . . . . . . . . . . .
        </Columns>
    </MasterTableView>
    <ClientSettings Selecting-CellSelectionMode="MultiCell">
        <ClientEvents OnCellSelected="OnCellSelected" />
    </ClientSettings>
</telerik:RadGrid>

JS:
<script type="text/javascript">
    function OnCellSelected(sender, eventArgs) {
        var columnName = eventArgs.get_column().get_uniqueName();//Get Selected Cell Column UniqueName
        var data = eventArgs.get_gridDataItem().get_cell(columnName);//Access data of the Column
        alert(data.innerHTML);
   }
</script>

Thanks,
Princy
0
John
Top achievements
Rank 1
answered on 30 Jul 2013, 08:56 AM
Hi Princy,

Thanks for your reply, the example you have posted gets the selection at the time the cell is selected. In my scenario i'd like to do the following:

Select multiple cells (A1, A2, C5, D7) using Ctrl click, then press a button to get the selection so I can then process the selected cell values.

So when i use something like getSelected it returns all the cells i have previously selected, is there a way i can achieve this?

0
Princy
Top achievements
Rank 1
answered on 01 Aug 2013, 09:29 AM
Hi John,

May i suggest,one other option would be to push the selected cell values in a global array in the cellselected event and get the values in the button click event.Please try the below code snippet.

ASPX:
<telerik:RadGrid ID="RadGrid1" runat="server" >
            <MasterTableView >
                <Columns>
                    <telerik:GridBoundColumn UniqueName="OrderID" DataField="OrderID" HeaderText="OrderID" />
                    <telerik:GridBoundColumn DataField="ShipCity" HeaderText="ShipCity" UniqueName="ShipCity" />
                    <telerik:GridBoundColumn DataField="EmployeeID" HeaderText="EmployeeID" UniqueName="EmployeeID" />
                </Columns>
            </MasterTableView>
            <ClientSettings Selecting-CellSelectionMode="MultiCell">
                <ClientEvents OnCellSelected="OnCellSelected" />
            </ClientSettings>
     </telerik:RadGrid>
<asp:Button ID="Button1" runat="server" Text="Button" OnClientClick="OnClientClick();" />

JS:
<script type="text/javascript">
    var values = new Array();    
    function OnCellSelected(sender, eventArgs) {
         var data; 

       
var columnName = eventArgs.get_column().get_uniqueName();
        data = eventArgs.get_gridDataItem().get_cell(columnName);
        values.push(data.innerHTML);
    }
    function OnClientClick(sender, eventArgs) {
        var i;
        for (i = 0; i < values.length; i++) {
            alert(values[i]);
        }
    }
</script>

Thanks,
Princy

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