Get selected record from drop down changed

Hi there - I have a drop down embedded in a grid column. When I select an item from the drop down, I can get the selected row just fine (the row gets selected when drop down gets focus).


However, when I change the drop down selected item, the row un-selects and causes exception in change event handler.



Am I going about this the "right" way, or, is there perhaps a better solution/fix. Thank you.


3 Replies 1 reply marked as answer

JP Jeevakanth Palaniappan Syncfusion Team August 20, 2021 09:06 AM UTC

Hi Gordon, 

Greetings from Syncfusion support. 

We have validated your query and by default, the rows gets toggled when you click on the selected row. So the invoiceDto will be null if there is no selected records. If you  don’t want the rows gets toggled then we suggest you to set the EnableToggle property as false in the GridSelectionSettings. Please find the below code snippet, documentation and the sample for your reference. 



<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true"> 
    <GridSelectionSettings EnableToggle="false"></GridSelectionSettings> 
    <GridPageSettings PageSize="5"></GridPageSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn HeaderText="Customer Name" Width="150"> 
            <Template> 
                <SfDropDownList Placeholder="OrderID" ID="OrderID" TItem="KeyValuePair<string, int>" TValue="int" DataSource="@GetData()"> 
                    <DropDownListEvents TValue="int" TItem="KeyValuePair<string, int>" ValueChange="ValueChangehandler"></DropDownListEvents> 
                    <DropDownListFieldSettings Value="Value" Text="Key"></DropDownListFieldSettings> 
                </SfDropDownList> 
            </Template> 
        </GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText="Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
 
 
@code{ 
    public List<Order> Orders { get; set; } 
    SfGrid<Order> Grid { get; set; } 
 
    public IEnumerable<KeyValuePair<string, int>> GetData() { 
        var actionList = new List<KeyValuePair<string, int>>(); 
        actionList.Add(new KeyValuePair<string, int>("One", 1)); 
        actionList.Add(new KeyValuePair<string, int>("Two", 2)); 
        return actionList; 
    } 
 
    public async Task ValueChangehandler(Syncfusion.Blazor.DropDowns.ChangeEventArgs<int, KeyValuePair<string,int>> args) 
    { 
        var SelectedRecords = await Grid.GetSelectedRecordsAsync().ConfigureAwait(false); 
        var check = SelectedRecords.FirstOrDefault(); 
    } 

} 

Get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Marked as answer

GO Gordon August 20, 2021 06:28 PM UTC

The level of support you guys offer is second-to-none! Thank you.



JP Jeevakanth Palaniappan Syncfusion Team August 23, 2021 05:54 AM UTC

Hi Gordon, 

You are most welcome. Get back to us if you have any other queries. 

Regards, 
Jeevakanth SP. 


Loader.
Up arrow icon