Parse RadGrid Rows

3 posts, 1 answers
  1. Greg
    Greg avatar
    16 posts
    Member since:
    Sep 2013

    Posted 22 Nov 2013 Link to this post

    I've spent the last few hours looking through the forums, as I suspect what I am doing is common.  So I am hoping you can point me to a sample of how to do this.

    All I am looking to do is parse the rows of a grid and capture the values in a couple of columns, then use that to call an AJAX class. 

    Here's the basic idea.  The web page loads a list of users with fields for first, middle, and last.  There is an execute search button that will run through the grid rows and capture the first, middle, last name and fire off an Ajax call that will verify if the name was found in our database.  When that button is pressed, it calls a JavaScript function.  That function needs to start with the first row, capture the first, middle, and last name columns values, and execute the search using AJAX.  The search will return a boolean, which will then be displayed as a string in the last column on the grid.

    I'm thinking something like the following, but I do not know how to get the parsing of the grid and rows to work correctly.

    Can you point me to a sample or explain how to do this?

    Best regards,

    function ExecuteSdnSearch() {
        //var grid = $find("<%=RadGrid1.ClientID %>");
        grid = $find("ctl00_MainContent_RadGrid1");
        var masterTableView = grid.get_masterTableView();
        for (var i = 0; i < length; i++) {
            var row = masterTableView.get_dataItems["Uid"];
            var cell = masterTableView.getCellByColumnUniqueName(row, "Uid");
            if (cell != null) uid = cell.innerHTML;
            cell = masterTableView.getCellByColumnUniqueName(row, "FirstName");
            if (cell != null) firstname = cell.innerHTML;
            cell = masterTableView.getCellByColumnUniqueName(row, "MiddleName");
            if (cell != null) middlename = cell.innerHTML;
            cell = masterTableView.getCellByColumnUniqueName(row, "LastName");
            if (cell != null) lastname = cell.innerHTML;
            // Execute AJAX Search
            var boolResult = AjaxService.SdnSearch(firstname, middlename, lastname, ExecuteSdnSearchCallBack);        
    function ExecuteSdnSearchCallback(bool) {
        // Update RadGrid Status Column
        cell = masterTableView.getCellByColumnUniqueName(row, "Status");
        cell.innerHTML = (string)bool; 
  2. Answer
    Jayesh Goyani
    Jayesh Goyani avatar
    2733 posts
    Member since:
    May 2010

    Posted 25 Nov 2013 Link to this post

    <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Forum.aspx.cs" Inherits="Forum" %>
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
    <!DOCTYPE html>
    <head runat="server">
        <script src="Script/jquery-1.10.2.min.js"></script>
        <telerik:RadCodeBlock ID="RadCodeBlock1" runat="server">
                function ExecuteSdnSearch() {
                    var grid = $find("<%=RadGrid1.ClientID %>");
                    var masterTableView = grid.get_masterTableView();
                    var Rows = masterTableView.get_dataItems();
                    for (var i = 0; i < Rows.length; i++) {
                        var row = Rows[i];
                        var firstname = '';
                        var cell = masterTableView.getCellByColumnUniqueName(row, "Name");
                        if (cell != null) {
                            firstname = cell.innerHTML;
                            url: "Forum.aspx/GetSomething",
                            type: "GET",
                            async: false,
                            dataType: "json",
                            contentType: "application/json; charset=utf-8",
                            success: function (res) {
                                cell = masterTableView.getCellByColumnUniqueName(row, "ID");
                                cell.innerHTML = res.d;
                            error: function (res) { alert("error"); }
                    return false;
        <form id="form1" runat="server">
            <telerik:RadScriptManager ID="RadScriptManager1" runat="server"></telerik:RadScriptManager>
            <telerik:RadGrid ID="RadGrid1" runat="server" AutoGenerateColumns="false" OnNeedDataSource="RadGrid1_NeedDataSource"
                        <telerik:GridBoundColumn DataField="Name" UniqueName="Name" HeaderText="Name">
                        <telerik:GridBoundColumn DataField="ID" UniqueName="ID" HeaderText="ID">
            <asp:Button ID="Button1" runat="server" Text="ExecuteSdnSearch" OnClientClick="return ExecuteSdnSearch();" />

    public partial class Forum : System.Web.UI.Page
        protected void Page_Init(object source, System.EventArgs e)
        protected void Page_Load(object sender, EventArgs e)
        protected void RadGrid1_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
            DataTable dt = new DataTable();
            dt.Columns.Add("ID", typeof(int));
            dt.Columns.Add("Name", typeof(string));
            dt.Columns.Add("Contact", typeof(DateTime));
            dt.Rows.Add(1, "name1", DateTime.Now);
            dt.Rows.Add(2, "name2", DateTime.Now);
            dt.Rows.Add(3, "name3", DateTime.Now);
            RadGrid1.DataSource = dt;
        [ScriptMethod(UseHttpGet = true)]
        public static string GetSomething()
            //write your logic here
            return "got something_" + new Random().Next(9,19874);

    Jayesh Goyani
  3. Greg
    Greg avatar
    16 posts
    Member since:
    Sep 2013

    Posted 25 Nov 2013 Link to this post

    Jayesh: Thanks for posting the sample.  I was able to work through my issue using your sample to how to retrieve the cell values from the grid. 

    Best regards,
Back to Top