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

Adding javascript to a GridFilteringItem control from code behind

1 Answer 67 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 24 Mar 2009, 03:47 PM
Hi,

I'd like to add a javascript function to the links of the menu items, for the onClick event.  The problem is I cannot find the the appropriate controls in the control hierarchy.  Here is what I've done so far :

private

 

void myFunction(GridFilteringItem item)
{

 

    foreach (TableCell cell in item.Cells)

    {

 

        foreach (Control c in cell.Controls)

        {

 

            if (c is GridFilterMenu)

            {

 

                GridFilterMenu gridFilterMenu = c as GridFilterMenu;

 

                // Find the links in the gridFilterMenu
                // Add javascript to the onClick event

            }

        }

    }

}

Using the debugger, I found out that the GridFilterMenu is not contained in the cell.  Where should I look for it?

Thank you very much!

M.

 

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 25 Mar 2009, 04:50 AM
Hello Martin,

You can try out the following code instead to add onClick attributes to the filtermenu items of the grid:
c#:
 protected void RadGrid1_ItemDataBound(object sender, GridItemEventArgs e) 
    { 
        GridFilterMenu filtermenu = RadGrid1.FilterMenu; 
        foreach (RadMenuItem item in filtermenu.Items) 
        { 
            item.Attributes.Add("onClick""return menu();"); 
        } 
   } 

js:
<script type="text/javascript"
function menu() 
 alert('hi'); 
</script> 

Thanks
Princy.
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or