Get Row Reference from SfDropDown in Grid

How do I reference row data from SfDropDownButton in a grid.  I am following: https://www.syncfusion.com/forums/153726/access-context-menu-ref-from-datagrid but confused.

I need to get employeeid so I can redirect.

GridColumn Field="@(nameof(RIAEmployee.EmployeeID))" HideAtMedia="(min-width: 700px)" IsPrimaryKey="true" HeaderText="EID" TextAlign="TextAlign.Right" Visible="false"></GridColumn>                
</GridColumn>
                        <GridColumn Field="@(nameof(RIAEmployee.EmployeeID))" HeaderText="Action" TextAlign="TextAlign.Center" Width="120">
                            <Template>
                                @{
                                    var riaemployee = (context as RIAEmployee);
                                    <SfDropDownButton Content="Actions">
                                        <DropDownButtonEvents ItemSelected="ItemSelected" >
                                        </DropDownButtonEvents>
                                        <DropDownMenuItems>
                                            <DropDownMenuItem Text="Edit"></DropDownMenuItem>
                                            <DropDownMenuItem Text="Delete"></DropDownMenuItem>
                                            <DropDownMenuItem Text="Copy"></DropDownMenuItem>
                                        </DropDownMenuItems>
                                    </SfDropDownButton>
                                }
                            </Template>
                        </GridColumn>



    private void ItemSelected(MenuEventArgs args)
    {
//how do i get employeeid        
var selectedItem = args.Item.Text;

    }





1 Reply 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team April 21, 2021 03:43 AM UTC

Hi Lynch,  
 
Thanks for contacting Syncfusion support.  
 
Query: “How do I reference row data from SfDropDownButton in a grid. 
 
We have analyzed your query and we suggest you to achieve your requirement by passing the context variable as an argument to ItemSelected event handler. Refer the below code example 
 
<SfGrid DataSource="@Employees" AllowPaging="true">    
    <GridColumns> 
        <GridColumn HeaderText="Employee Image" TextAlign="TextAlign.Center" Width="120"> 
            <Template> 
                @{ 
                    var employee = (context as EmployeeData); 
                    <SfDropDownButton Content="Actions"> 
                        <DropDownButtonEvents ItemSelected="@((args)=>ItemSelected(args,employee))"> 
                        </DropDownButtonEvents> 
                        <DropDownMenuItems> 
                            <DropDownMenuItem Text="Edit"></DropDownMenuItem> 
                            <DropDownMenuItem Text="Delete"></DropDownMenuItem> 
                            <DropDownMenuItem Text="Copy"></DropDownMenuItem> 
                        </DropDownMenuItems> 
                    </SfDropDownButton> 
  
                } 
            </Template> 
        </GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.EmployeeID) HeaderText="Employee ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.FirstName) HeaderText="First Name" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.Title) HeaderText="Title" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(EmployeeData.HireDate) HeaderText="Hire Date" Format="d" TextAlign="TextAlign.Right" Width="150"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    public List<EmployeeData> Employees { getset; } 
    private void ItemSelected(MenuEventArgs args, EmployeeData emp) 
    { 
  
        //how do i get employeeid         
        var id = emp.EmployeeID; 
        var selectedItem = args.Item.Text; 
    } 
 
 
For your convenience we have prepared a sample which can be downloaded from below  
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 
 
 


Marked as answer
Loader.
Up arrow icon