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

How to select a grid row using javascript.

3 Answers 118 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Ron
Top achievements
Rank 1
Ron asked on 03 Aug 2011, 12:55 PM
Hi,

Can you tell me if there is a way to select a row in a grid with javascript? For instance, lets say I did a rebind on the client and immediately following the rebind I wanted to have row 3 of the grid selected and highlighted. Is that possible?

Thanks,
Ron.

3 Answers, 1 is accepted

Sort by
0
Accepted
Shinu
Top achievements
Rank 2
answered on 03 Aug 2011, 01:27 PM
Hello Ron,

Try the following code snippet to select a row from client side.

Javascript:
function ButtonClick()
{
      var grid = $find("<%=RadGrid1.ClientID %>");
      var MasterTable = grid.get_masterTableView();
      MasterTable.get_dataItems()[2].set_selected(true);
}

Thanks,
Shinu.
0
Ron
Top achievements
Rank 1
answered on 04 Aug 2011, 02:39 AM
This worked, thanks!
0
Ron
Top achievements
Rank 1
answered on 04 Aug 2011, 03:24 AM
On second thought it did not work...sort of. Today when I tried it from a different location if my memory served me correctly it did work on an xp computer with ie 8 now tonight at home with ie 9 on windows 7 its not working correctly. It does attempt to select the row, it highlights for about a second then goes away. Here's my code.
function UpdateStatus() {
               UserWebService.UpdateStatus(Id);
               $find("<%= grdStaff.ClientID %>").get_masterTableView().rebind();
 
               var status = document.getElementById("<%= lblStatus.ClientID %>");
               status.innerHTML = "Active";
 
               var grid = $find("<%= grdStaff.ClientID %>");
               var MasterTable = grid.get_masterTableView();
               MasterTable.get_dataItems()[rowIndex1].set_selected(true);
 
               return false;
           }
Tags
Grid
Asked by
Ron
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Ron
Top achievements
Rank 1
Share this question
or