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

Client side programmatically row selection

2 Answers 116 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jc
Top achievements
Rank 1
Jc asked on 31 May 2013, 01:16 PM
Hi,

I'm trying to select radgridview row programmatically on client side with DataKeyValue.
I'd like the selected row background to be modified also. 
Using RadControls for ASP.NET AJAX Q1 2013. Here is my sample code, but not working properly:

var Rows = $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems();
 
                   for (var i = 0; i < Rows.length; i++) {
                       var row = Rows[i];
                       if (row != null && row.getDataKeyValue("Id") != null && row.getDataKeyValue("Id") == id) {
                            $find("<%=RadGrid1.ClientID %>").get_masterTableView().get_dataItems()[i].set_selected("true");
                            break;
                       }
                   }

Any idea?
Thank you.
KR,
JC

2 Answers, 1 is accepted

Sort by
0
Accepted
Jayesh Goyani
Top achievements
Rank 2
answered on 01 Jun 2013, 05:33 AM
Hello,

Please try with below code snippet.

<asp:Button ID="btnTest" runat="server" Text="Test" OnClientClick="GetDate(); return false;" />
function GetDate() {
               var grid = $find("<%=RadGrid1.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];
                       var keyId = row.getDataKeyValue("ID");
                       if (keyId == "YourCondition") {
                           row.set_selected(true);
                       }
                   }
               }
           }


Thanks,
Jayesh Goyani
0
Jc
Top achievements
Rank 1
answered on 03 Jun 2013, 07:26 AM
Thank you for your help.

I tried your snippet, and had to clear the slectedRows before. Here is the full method:
function selectRow(grid, dataKeyName, selectedDataKeyValue) {
                grid.clearSelectedItems();
                var Rows = grid.get_masterTableView().get_dataItems();
                for (var i = 0; i < Rows.length; i++) {
                    var row = Rows[i];
                    var keyId = row.getDataKeyValue(dataKeyName);
                    if (keyId.toUpperCase() == selectedDataKeyValue.toUpperCase()) {
                        {
                            row.set_selected(true);
return;
                        }
                    }
                }
            }

KR,
JC
Tags
Grid
Asked by
Jc
Top achievements
Rank 1
Answers by
Jayesh Goyani
Top achievements
Rank 2
Jc
Top achievements
Rank 1
Share this question
or