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

select all items onclick of the linkbutton

1 Answer 18 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Savyo
Top achievements
Rank 1
Savyo asked on 18 Jul 2012, 01:07 PM
Hi,
     I have a linkbutton in the commanditemtemplate of my radgrid. I want to select all the items in my radgrid on clicking the linkbutton in clientside. Please guide me.
thanks in advance
savyo

1 Answer, 1 is accepted

Sort by
0
Jayesh Goyani
Top achievements
Rank 2
answered on 18 Jul 2012, 01:12 PM
Hello,

function SelectAllRow() {
               var grid = $find("<%= RadGrid2.ClientID %>");
 
               if (grid) {
                   var MasterTable = grid.get_masterTableView();
                   var Rows = MasterTable.get_dataItems();
                   for (var i = 0; i < Rows.length; i++) {
                       var row = Rows[i];
                       row.set_selected(true);
                   }
               }
 
               return false;
           }
<telerik:RadGrid ID="RadGrid2" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid2_NeedDataSource"
          AllowMultiRowSelection="true">
            <MasterTableView DataKeyNames="ID" ClientDataKeyNames="ID" CommandItemDisplay="Top">
                <CommandItemTemplate>
                    <asp:LinkButton ID="Buttontest" runat="server" Text="Select All Row" OnClientClick="return SelectAllRow();" />
                </CommandItemTemplate>
                <Columns>
                    <telerik:GridBoundColumn HeaderText="ID" DataField="ID" UniqueName="ID">
                    </telerik:GridBoundColumn>
                    <telerik:GridBoundColumn HeaderText="Name" DataField="Name" UniqueName="Name">
                    </telerik:GridBoundColumn>
                </Columns>
            </MasterTableView>
            <ClientSettings>
                <Selecting AllowRowSelect="true" />
            </ClientSettings>
        </telerik:RadGrid>
protected void RadGrid2_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
    {
 
        dynamic data = new[] {
                new { ID = 1, Name ="Name1"},
                new { ID = 2, Name = "Name2"},
                new { ID = 3, Name = "Name3"}
            };
        RadGrid2.DataSource = data;
 
 
    }


Thanks,
Jayesh Goyani
Tags
Grid
Asked by
Savyo
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Share this question
or