eventArgs.get_itemIndexHierarchical();

1 Answer 266 Views
Grid
anna
Top achievements
Rank 1
Bronze
Iron
anna asked on 22 Jan 2022, 06:50 AM | edited on 23 Jan 2022, 12:14 PM

In Telerik:RadGrid , ASP.NET , Web,

<ClientSettings EnablePostBackOnRowClick="true">  
<Selecting RowClick="true" /> 
</ClientSettings>   
protected void RadGrid_ItemConmmand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RowClick")
            {              
                var text = "";
                text += "Row was clicked";
                text += ", Index: " + eventArgs.get_itemIndexHierarchical();
                alert(text);
            }

Is the grammar correct?

Please Help Me

1 Answer, 1 is accepted

Sort by
0
Doncho
Telerik team
answered on 26 Jan 2022, 01:24 PM

Hi Anna,

Please refer to the answer I have posted to your question on a similar topic - https://www.telerik.com/forums/eventargs-get-gridcolumn-get-element-cellindex

In short, you can find detailed information on how to access Grid rows both on the client and on the server-side in our documentation:

Here is a piece of code you can test to reach the row index on the client-side:

<script>
    function rowClick(sender, eventArgs) {
        var text = "";
        text += "Column was clicked";
        text += ", Index: " + eventArgs.get_itemIndexHierarchical();
        alert(text);
    }
</script>
<telerik:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" Width="800px" OnNeedDataSource="RadGrid1_NeedDataSource">
    <ClientSettings>
        <ClientEvents OnRowClick="rowClick" />
    </ClientSettings>

Note that enabling the EnablePostBackOnRowClick property, in this case, is not needed as the logic is executed entirely on the client-side, and triggering a postback would prevent that.

Kind regards,
Doncho
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

anna
Top achievements
Rank 1
Bronze
Iron
commented on 26 Jan 2022, 04:09 PM | edited



You misunderstood the gist of the question. 

please see source below. I am using ASP.NET RadGrid Web

protected void RadGrid_ItemConmmand(object source, GridCommandEventArgs e)

I want to implement "protected void RadGrid_ItemConmmand" function in .cs file(ASP.NET).

About RowClick... 

So I wrote the source code below,It does not work. 
This source doesn't work.

Is the syntax in the source below correct?

<ClientSettings EnablePostBackOnRowClick="true">  

<Selecting RowClick="true" /> 
</ClientSettings>   
protected void RadGrid_ItemConmmand(object source, GridCommandEventArgs e)
        {
            if (e.CommandName == "RowClick")
            {              
                var text = "";
                text += "Row was clicked";
                text += ", Index: " +eventArgs.get_itemIndexHierarchical();
                alert(text);
            }

}

please please help me. keep waiting for reply

Doncho
Telerik team
commented on 31 Jan 2022, 01:47 PM

Hi Anna,

Here is a piece of code you can try:

protected void RadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "RowClick")
    {
        var itemIndex = e.Item.ItemIndexHierarchical;
        //execute custom server-side logic here 

        // to force alert() after postback you can execute custom JavaScript from the server-side
        //https://docs.telerik.com/devtools/aspnet-ajax/knowledge-base/common-executing-javascript-code-from-server-side-in-web-forms-and-aspnet-ajax
        string scriptstring = "alert('Row was clicked, Index: " + itemIndex + "');";
        ScriptManager.RegisterStartupScript(Page, Page.GetType(), "myalert", scriptstring, true);
    }
}

Note that RowClick is an invalid property inside the <Selecting> client-side settings of the RadGrid and normally adding it should result in a compile-time error. See available properties inside the Selecting tag - Telerik.Web.UI.GridSelecting

Side note: alert() is a standard client-side method exposed by the Window object, see Window alert(). With this in mind calling directly from the server-side is not possible. Instead, if alert should be shown after a postback, you execute custom JavaScript from the server as per the instructions in our Executing JavaScript Code from Server-side in Web Forms and ASP.NET AJAX

anna
Top achievements
Rank 1
Bronze
Iron
commented on 31 Jan 2022, 05:04 PM | edited

Hello.

I need help.

I need the coordinates of Column + Row of the selected cell in Radgrid.
Is the syntax of the source I attached correct?

please reply.

keep waiting for your reply

I want to communicate with client side and server side.


In Server Side(ASP.NET), 
<ClientSettings>
    <Selecting CellSelectionMode="MultiCell" />
    <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    <ClientEvents OnCellSelected="cellSelected" />
</ClientSettings>

In JavaScript,
function cellSelected(sender, args)
{
            var selectedRow = args.get_row();
            var selectedColumn = args.get_column();
            var dataItem = args.get_gridDataItem();
            var tableView = args.get_tableView();
            var cellIndex = args.get_cellIndexHierarchical();
            var output = String.format("The selected cell is located in column with name: " + selectedColumn.get_uniqueName() + " and in row with index: " + dataItem.get_itemIndexHierarchical() + ". This cell has index " + cellIndex + " and it is part from " + tableView.get_name() + ".");

sender.get_masterTableView().fireCommand("cellSelected",    ????????????? );

}



Is the syntax of the source I attached correct?

To get the Selected Column&Row Coordinate

Client Side (aspx.cs)

protected void gv_ItemConmmand(object source, GridCommandEventArgs e)
{
if (e.CommandName == "cellSelected")
    {
 var clickedColumnName = e.CommandArgument.ToString();

         // Label1.Text = clickedColumnName;
     }
 }

Do you have any other code from this source?

In Server Side

<ClientSettings>
    <Selecting CellSelectionMode="MultiCell" />
    <Scrolling AllowScroll="true" UseStaticHeaders="true" />
    <ClientEvents OnCellSelected="cellSelected" />
</ClientSettings>

In Client Side

protected voidRadGrid1_ItemCommand(object sender, GridCommandEventArgs e)
{
    if (e.CommandName == "CellClick")
    {
        var selectedColumn = e.Item.selectedColumn.get_uniqueName();
        var selectedRow = e.Item.get_row();
    }
}                     

Tags
Grid
Asked by
anna
Top achievements
Rank 1
Bronze
Iron
Answers by
Doncho
Telerik team
Share this question
or