We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
close icon

DropDownBox in Grid displays first Item when adding new record?

When I add a new record in a grid the DropDownBox displays the first item and not just a blank box.  I just want a blank box and if the user doesn't make a selection have it just remain blank/null.  It's a optional field anyways.

1 Reply

MS Mani Sankar Durai Syncfusion Team December 2, 2016 12:29 PM UTC

Hi Michael, 


Thanks for contacting Syncfusion support. 


We have analyzed your query and based on that we have prepared a sample that can be downloaded from the below link. 

 
 
By default when adding the records in grid it will show the blank value for the dropdown columns and if user doesn’t select anything it will remains blank value. Suppose, if you set DefaultValue property for that particular column then it will shows that value while adding a record. 
 
 
To show the dropdown value as blank value or null we suggest you to pass the empty data to the dropdown datasource initially when binding or by using addItem method in dropdown(when DefaultValue is set). Using selectItemByText we can able to make the dropdown value as null when user doesn’t select any items. 
 
 
Please refer the below code example. 

[index.cshtml] 
@(Html.EJ().Grid<MVCSampleBrowser.Models.EditableOrder>("Grid") 
        .Datasource((IEnumerable<object>)ViewBag.datasource) 
        .AllowPaging() 
...                .ClientSideEvents(eve => eve.ActionComplete("complete")) 
        .Columns(col => 
            { 
                ... 
             }) 
              ) 
 
<script> 
     
    function complete(args) { 
       if (args.requestType == 'add') { 
            var dropdown = $("#GridEmployeeID").ejDropDownList("instance"); 
            $('#GridEmployeeID').ejDropDownList("addItem", { text: "" }); 
            dropdown.selectItemByText(""); 
           } 
    } 
</script> 



From the above code example, we have pass the empty data to the dropdown datasource for the particular column and by using selectItembyText or index we can get the blank value in dropdown. 

Please refer the documentation link. 



If you still face the issue please get back to us with the following details, 
1.       Share the screenshot of the issue that you have faced. 
2.       Share the full grid code. 
3.       Share the datasource for the dropdown. 
4.       If possible please reproduce the issue in the above attached sample. 
The provided information will help us to analyze the issue and provide you the response as early as possible. 

Please let us know if you need further assistance. 


Regards, 
Manisankar Durai. 


Loader.
Live Chat Icon For mobile
Up arrow icon