Hi Sid,
Thanks for contacting Syncfusion support.
Query 1: How to Connect DropDownList to SQL DataSource? Is this feature available for ASP.NET Core? Or, can I mix in the ASP.NET MVC DropdownList which has viable documentation?
Yes, it is available in ASP.NET Core. There is no need to use MVC Dropdownlist in Core Project as Core Dropdownlist supports all the features available MVC Dropdownlist.
In order to connect a SQL data source to dropdownlist, you have to create a list and add the required data from the data table to the list using SQL command and return the list to the view page. Have a look at the below code snippet.
Controller page
List<Orders> data = new List<Orders>();
public IActionResult Index()
{
string RootPath = _hostingEnvironment.ContentRootPath;
using (con)
{
con.Open();
SqlDataReader myReader = null;
SqlCommand myCommand = new SqlCommand("select * From [Orders]",
con);
myReader = myCommand.ExecuteReader();
while (myReader.Read())
{
data.Add(new Orders(myReader["ShipName"].ToString()));
}
con.Close();
ViewBag.datasource = data;
}
return View(); |
In the view page, bind ViewBag list to the dropdownlist’s datasource API. Have a look at the following code snippet.
View Page
<ej-drop-down-list id="bikeList" datasource="(IEnumerable<Orders>)ViewBag.datasource" watermark-text="Select ShipName"width="100%">
<e-drop-down-list-fields text="ShipName" />
</ej-drop-down-list> |
We have included a sample for your convenience. Please refer to the Sample link.
Regards,
Prince