I have the below code where I am populating a dropdown list in ASP.NET with JSON data from a URL. The selection I then want to insert into a SQL table that has EmployeeID field.
I am getting below error message
Databinding methods such as Eval(), XPath(), and Bind() can only be used in the context of a databound control.
What am I missing? Thanks for all your help
HTML
<asp:DropDownList runat="server" ID="ddlNames" SelectedValue='<%# Bind("EmployeeId") %>'>>
</asp:DropDownList>
Namespaces
C#
using System.Net;
using System.Web.Script.Serialization;
VB.Net
Imports System.Net
Imports System.Web.Script.Serialization
Code
C#
protected void Page_Load(object sender, EventArgs e)
{
string json = (new WebClient()).DownloadString("https://workforcedeveloper-api.hcso.fr.co.hennepin.mn.us/Directory");
JavaScriptSerializer serializer = new JavaScriptSerializer();
List<Person> persons = serializer.Deserialize<List<Person>>(json);
ddlNames.DataSource = (from p in persons
select string.Format("{0} {1} {2}", p.firstName, p.middleName, p.lastName));
ddlNames.DataBind();
}
public class PhoneNumber
{
public string phoneType { get; set; }
public string phoneNumber { get; set; }
}
public class Person
{
public string firstName { get; set; }
public string middleName { get; set; }
public string lastName { get; set; }
public string email { get; set; }
public string currentUnit { get; set; }
public string currentRank { get; set; }
public List<PhoneNumber> phoneNumbers { get; set; }
}