c# - Get selected items in a RadGrid client-side - Stack Overflow

I want to get the values of the selected checkbox in a RadGrid.I have a radgrid, textbox and a button

I want to get the values of the selected checkbox in a RadGrid. I have a radgrid, textbox and a button as follows:

this._RadAjaxPanel.Controls.Add(RadGrid1);
this._RadAjaxPanel.Controls.Add(TextBox1);
this._RadAjaxPanel.Controls.Add(Buton1);

The radgrid id is set to RadGrid1 and

Button1.OnClientClick = "GetSelectedItems("+ this._RadGrid1 +")";

On click of the button a javascript is called where I want to know which rows have been selected. The javascript function is as follows but it is not correct:

 function GetSelectedItems(grid) {           
    var selectedRows = grid.get_selectedItems();
    for (var i = 0; i < selectedRows.length; i++) {
        var row = selectedRows[i];
        var cell = grid.getCellByColumnUniqueName(row, "CategoryID")
        //here cell.innerHTML holds the value of the cell    
    }
}

Please let me know how can I get the selected rows.

I want to get the values of the selected checkbox in a RadGrid. I have a radgrid, textbox and a button as follows:

this._RadAjaxPanel.Controls.Add(RadGrid1);
this._RadAjaxPanel.Controls.Add(TextBox1);
this._RadAjaxPanel.Controls.Add(Buton1);

The radgrid id is set to RadGrid1 and

Button1.OnClientClick = "GetSelectedItems("+ this._RadGrid1 +")";

On click of the button a javascript is called where I want to know which rows have been selected. The javascript function is as follows but it is not correct:

 function GetSelectedItems(grid) {           
    var selectedRows = grid.get_selectedItems();
    for (var i = 0; i < selectedRows.length; i++) {
        var row = selectedRows[i];
        var cell = grid.getCellByColumnUniqueName(row, "CategoryID")
        //here cell.innerHTML holds the value of the cell    
    }
}

Please let me know how can I get the selected rows.

Share Improve this question edited Jun 9, 2014 at 17:31 R B asked Jun 9, 2014 at 17:01 R BR B 4233 gold badges8 silver badges19 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Here is how to get whether or not a checkbox is selected. I am using a GridTemplateColumn with a CheckBox as the ItemTemplate, which Telerik always suggests using over the GridCheckBoxColumn.

The trick is to get the inner HTML in the cell, and parse out the name of the control. The cell value will be something like id=cbxRow where the CheckBox control's ID is cbxRow like in the below example.

JavaScript:

var grid = $find("RadGrid1");
var masterTableView = grid.get_masterTableView();
var selectedRows = masterTableView.get_selectedItems();

for (var i = 0; i < selectedRows.length; i++) {
    var cellCB = masterTableView.getCellByColumnUniqueName(row, "CB");
    var innerCB = cellCB.innerHTML;
    var locId = innerCB.indexOf("id=");
    var locIdEnd = innerCB.indexOf("\" ", locId);
    var idVal = innerCB.substr(locId + 4, locIdEnd - locId - 4);
    var cbx = document.getElementById(idVal);
    if (cbx.checked) {
        alert("The checkbox is checked!");
    }
    else {
        alert("The checkbox is not checked!");
    }
}

ASPX:

<telerik:GridTemplateColumn UniqueName="CB" ...>
    <ItemTemplate>
        <asp:CheckBox ID="cbxRow" runat="server">
    </ItemTemplate>
</telerik:GridTemplateColumn>

I have tried the following, which solved my issue:

this._Button1.Attributes.Add("OnClick", "GetSelectedItems('" + _RadGrid1.ClientID + "');return false;");

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744402341a4572452.html

相关推荐

  • c# - Get selected items in a RadGrid client-side - Stack Overflow

    I want to get the values of the selected checkbox in a RadGrid.I have a radgrid, textbox and a button

    6天前
    40

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信