SfDropDownList WebApiAdaptor refresh data

How to refresh data dynamically via c#?


<SfDropDownList TValue="int?" TItem="SimpleList" @bind-Value="@_model.MarketSegment2Id" AllowFiltering=true>
<SfDataManager Headers="@HeaderData" Url="api/Test1" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true" />
<DropDownListFieldSettings Text="Name" Value="Id" />
</SfDropDownList>

4 Replies

AS ashimaz December 7, 2020 04:12 PM UTC

To elaborate in details I am using WebApiAdaptor to get data for below two dropdownlist. Once region is selected countries will be loaded to second dropdownlist based on selected region, Im using follwing code on ValueChange.

this.RegionQuery = new Query().Where(new WhereFilter() { Field = "Region", Operator = "equal", value = args.ItemData.Name, IgnoreCase = false, IgnoreAccent = false });

Please assist.


<div class="form-group">
<label for="@_model.RegionId">Region</label>
<SfDropDownList TValue="int" TItem="SimpleList" @bind-Value="@_model.RegionId" AllowFiltering=true >
<SfDataManager Headers="@HeaderData" Url="api/GetCountryRegions" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true" />
<DropDownListFieldSettings Text="Name" Value="Id" />
<DropDownListEvents TItem="SimpleList" TValue="int" ValueChange="RegionIdValueChange"></DropDownListEvents>
</SfDropDownList>
</div>
<div class="form-group">
<label for="@_model.CountryId">Country</label>
<SfDropDownList @ref="SfDropDownListCountryId" TValue="int" TItem="CountryList" @bind-Value="@_model.CountryId" AllowFiltering=true Query="@RegionQuery">
<SfDataManager Headers="@HeaderData" Url="api/GetCountries" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true" />
<DropDownListFieldSettings Text="Name" Value="Id" />
</SfDropDownList>
</div>


BC Berly Christopher Syncfusion Team December 14, 2020 05:29 PM UTC

Hi Ashimaz, 
  
Greetings from Syncfusion support. 
  
We have prepared the cascading sample for the DropDownList component with Web API adaptor and attached it below.  
  
  
 
@using WebAPI.Data 
@using Syncfusion.Blazor 
@using Syncfusion.Blazor.DropDowns 
@using Syncfusion.Blazor.Data 
<SfDropDownList TValue="string" TItem="Countries" @bind-Value="@countryVal"> 
    <SfDataManager Url="api/Country" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager> 
    <DropDownListFieldSettings Value="CountryId" Text="CountryName" /> 
    <DropDownListEvents TItem="Countries" TValue="string" ValueChange="ChangeCountry"></DropDownListEvents> 
</SfDropDownList> 
<SfDropDownList TValue="string" TItem="States" @bind-Value="@StateValue" Enabled="@EnableStateDropDown" Query="@StateQuery"> 
    <SfDataManager Url="api/State" Adaptor="Adaptors.WebApiAdaptor" CrossDomain="true"></SfDataManager> 
    <DropDownListFieldSettings Value="StateId" Text="StateName" /> 
</SfDropDownList> 
@code{ 
    public bool EnableStateDropDown = false; 
    public Query StateQuery = new Query(); 
    public string StateValue { get; set; } = null; 
 
    public string countryVal { get; set; } 
    public void ChangeCountry(ChangeEventArgs<string, Countries> args) 
    { 
        this.EnableStateDropDown = true; 
        this.StateQuery = new Query().Where(new WhereFilter() { Field = "CountryId", Operator = "equal", value = args.Value, IgnoreCase = false, IgnoreAccent = false }).RequiresCount(); 
        this.StateValue = null; 
    } 
} 

  
Regards, 
Berly B.C 



AS ashimaz December 14, 2020 05:39 PM UTC

Chat told me I will get reply in 48hrs, and since I didn't get a reply, I have solve this issue via DataSource without using WebApiAdaptor.

Thanks, I will test this using WebApiAdaptor.


VS Vignesh Srinivasan Syncfusion Team December 15, 2020 11:46 AM UTC

Hi Ashimaz, 
 
We apologize for the delay. We will wait for your reply. Please contact us if you require any further assistance. 
 
Regards, 
 
Vignesh Srinivasan. 


Loader.
Up arrow icon