Last post Jun 08, 2018 05:11 AM by Nan Yu
Jun 07, 2018 10:28 PM|tkhan17|LINK
I have a 'employee' table in MSSQL Server and I want to extract the 'employee position' column from that table to a dropdownlist on Visual Studio in Asp.Net. So when the user clicks on the dropdownlist, the data from the table gets directly extracted
and displays on the dropdownlist. I can edit and manually and put the data in the dropdownlist but there's about 60 rows in my table for that column. So I was wondering if there is a way I get get those data directly from MSSQL without manually putting it
in the dropdownlist.
Jun 08, 2018 05:11 AM|Nan Yu|LINK
You can bind DropDownList control using SqlDataSource in ASP.Net , for example :
<asp:DropDownList ID="ddlEmployees" runat="server" DataSourceID="SqlDataSource1"
DataTextField="EmployeeName" DataValueField = "EmployeeID" AppendDataBoundItems = "true">
<asp:ListItem Text="Please select" Value="" />
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:constr %>"
SelectCommand="SELECT (FirstName + ' ' + LastName) AS EmployeeName, EmployeeID FROM Employees">
Please refer to documents below for more details and explanation :