New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

How to get UniqueName of RadGrid column from controls inside

How to

Get the UniqueName of a grid column from DOM elements inside.

Doing this can let you know in which column events occur (e.g., the user clicks, or changes values in form elements).

In turn, you can use this to perform updates to the data source immediately without any postbacks - once you know the user input and the column name, you can call a service that will take the data, validate it, and store it in the database. You can even skip updating the UI because the user input is already there. To this end, the ItemTemplate of the GridTemplate columns is used so the user can immediately edit data.

A more robust example of client-side editing is available through the Batch Editing feature of the grid: Batch Editing.


Start from the element that fired the event inside the cell. For example, use its own events/attributes. Then, traverse the DOM (e.g, with jQuery) to get a reference to the grid and the cell. Now you can use the cell index in the <table> to get a reference to the column of the grid.

For example:

<telerik:RadScriptManager runat="server" ID="rsm1">
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.Core.js" />
        <asp:ScriptReference Assembly="Telerik.Web.UI" Name="Telerik.Web.UI.Common.jQuery.js" />
    var $ = $telerik.$;//get jQuery to use for the DOM traversal
    function sendData(elem) {
        //get the value of the DOM element, can vary depending on the element that fires the event
        var currValue = elem.value;
        //traverse the DOM to reference the grid and the concrete cell
        //with that, we can get the UniqueName of the column from which the event originats
        var grid = $(elem).parents("div.RadGrid").first()[0].control;
        var cellIndex = $(elem).parents("td").first()[0].cellIndex;
        var columnName = grid.get_masterTableView().get_columns()[cellIndex].get_uniqueName();
        //we can now use the unique name and the new value to call a service that can update the data source
<telerik:RadGrid runat="server" ID="rg1" OnNeedDataSource="rg1_NeedDataSource">
            <telerik:GridTemplateColumn UniqueName="firstColumn">
                    <asp:DropDownList runat="server" ID="firstDdl" onchange="sendData(this)">
                        <asp:ListItem Text="text1" Value="1" />
                        <asp:ListItem Text="text2" Value="2" />
            <telerik:GridTemplateColumn UniqueName="secondColumn">
                    <asp:DropDownList runat="server" ID="secondDdl" onchange="sendData(this)">
                        <asp:ListItem Text="text1" Value="1" />
                        <asp:ListItem Text="text2" Value="2" />
            <telerik:GridTemplateColumn UniqueName="thirdColumn">
                    <asp:TextBox runat="server" ID="firstTb" onblur="sendData(this)" />
In this article