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

Accessing cell content on selection

4 Answers 80 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Robert
Top achievements
Rank 1
Robert asked on 10 Dec 2008, 05:55 PM
Hi,

I vahe implemented row selection using the EnablePostBackOnRowClick property. How can I access the content of a specific cell in the selected row from the event handler (OnItemCommand)?

Best regards,
Robert

4 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 10 Dec 2008, 06:29 PM
Hello Robert,

Please test the following code-snippets:
<script language="javascript" type="text/javascript"
    function HandleCellClick(sender, args) 
    { 
        var targetCell = args.get_domEvent().target; 
        sender.get_masterTableView().fireCommand("CellClick", args.get_itemIndexHierarchical() + "|" + targetCell.innerHTML); 
    } 
</script> 

<ClientSettings Selecting-AllowRowSelect="true" ClientEvents-OnRowSelected="HandleCellClick" /> 

protected void RadGrid1_ItemCommand(object source, GridCommandEventArgs e) 
    if (e.CommandName == "CellClick"
    { 
        string[] args = e.CommandArgument.ToString().Split('|'); 
        RadGrid1.Items[int.Parse(args[0])].Selected = true
        RadAjaxManager1.Alert("Cell contents: \n" + args[1]); 
    } 

Let me know whether this helps.

Best regards,
Daniel
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
Robert
Top achievements
Rank 1
answered on 11 Dec 2008, 06:50 PM
Hi Daniel,

thank your for your reply. Unfortunately the code you provided does not work for me. It seems that my scenario is slightly different. I am catching the "RowClick" command not "CellClick". So what I actually want is to get access to the selected row and then iterate through it's cells.
Sorry, I didn't explain that clearly in my original post.

Best regards,
Robert
0
Princy
Top achievements
Rank 2
answered on 12 Dec 2008, 05:14 AM
Hello Robert,

you can try out the following code to achieve the required scenario.
cs:
protected void RadGrid2_ItemCommand(object source, GridCommandEventArgs e) 
    { 
        if (e.CommandName == "RowClick") 
        { 
            GridDataItem item = (GridDataItem)e.Item; 
            if (item.Selected) 
            { 
                foreach (GridColumn col in RadGrid2.Columns) 
                { 
                    string strtxt = item[col.UniqueName].Text; 
                } 
            } 
        } 
  } 

Thanks
Princy.



0
sumanth
Top achievements
Rank 2
answered on 01 Apr 2009, 12:59 PM
Hi
Danial

I am working on RADGRID , Accessing Cell Values.
I am trying with your code.
BUT My Scenario is little bit different 
That looks like this
All the dataTypes in the grid are same(int).
We have to select any cell (Multiple Selection Also) 
I need the same value to be displayed in ToolTip
If we selected Multipule Cells, I need the sum of the values of selection in the ToolTip.

Plz help me if U have any idea how to achive the same plz tell me


Thanks in Advance
Sumanth

 
Tags
Grid
Asked by
Robert
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Robert
Top achievements
Rank 1
Princy
Top achievements
Rank 2
sumanth
Top achievements
Rank 2
Share this question
or