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

Find out the clicked column in a row

3 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
David Cohen
Top achievements
Rank 1
David Cohen asked on 13 Apr 2010, 07:52 AM
Hi

My grid contain a few data bound columns and one templete column which contain a link button.
At the client side, when a user clicked on (or select) a row I need to find out whether he press the bound columns or the link button, and I need to know the values' of rhe cells in the selected row.

I know how to find the values in the RowSelected event, but I don't know how to find on which column he clicked.

Is there a way to find it ?

Thanks
David

P.S
I'm using RadGrid.Net2.dll Q1 2007 version (file version 5.0.1.0)

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 13 Apr 2010, 09:33 AM
Hello David Cohen,

I tried attaching onclick event for each cells in the grid and passed the ColumnUniquName as the paramter to the event handler. Then check for theColumnUniqueName in the RowSelected event to differentiating the columns clicked.

The code for attaching the onclick event for the cells:
 
    protected void RadGrid1_PreRender(object sender, EventArgs e) 
    { 
        foreach (GridDataItem item in RadGrid1.MasterTableView.Items) 
        { 
            foreach (GridColumn column in RadGrid1.MasterTableView.Columns) 
            { 
                item[column.UniqueName].Attributes.Add("onclick""getColumnCliecked('" + column.UniqueName + "');"); 
            } 
        } 
    } 

Client code for getting the column which I clicked:
 
<script type="text/javascript"
    var columnUniquName = ""
    function RowSelected(sender, args) { 
        if (columnUniquName == "EmployeeID") { 
            alert("Clicked on EmployeeID"); 
        } 
        . . . 
    } 
    function getColumnCliecked(cu) { 
        columnUniquName = cu; 
    } 
</script> 


-Shinu.
0
David Cohen
Top achievements
Rank 1
answered on 13 Apr 2010, 10:51 AM
Hi

Thanks for your reply.
It's work except one thing.

I do not get the RowSelected event in every cell, only the first column (which is a template column just for numbering the rows)

0
Richard
Top achievements
Rank 2
answered on 27 May 2010, 04:01 PM
David,

I'm not sure if it's too late to give you a hand with this but I found that you have to use the RadGrid_ItemDataBound event instead of the PreRender event to wire-up the javascript.  Here is a working snippet.  Hope it helps!

protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e)  
        {  
            GridDataItem item = e.Item as GridDataItem;  
            foreach (GridColumn column in RadGrid1.MasterTableView.RenderColumns)  
            {  
                if (column is GridBoundColumn)  
                {  
                    if (item is GridItem)  
                    {  
                        item[column.UniqueName].Attributes.Add("onclick""getColumnClicked('" + column.UniqueName + "');");  
                    }  
                }  
            }  
        } 

*Please note that I changed the JavaScript function to "getColumnClicked" to correct a spelling error.  You may need to update your code as well.

Regards,

Richard Lemmon
Tags
Grid
Asked by
David Cohen
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
David Cohen
Top achievements
Rank 1
Richard
Top achievements
Rank 2
Share this question
or