I am new to c# so bit stuck at what I thought was a very simple module. I just need to display data in the dropdown menu but getting some error while binding… or I will say even before binding. Here is what I am trying to do..I am really sorry if I am doing a very simple mistake but I tried my best & now I think I need some guidance..
CustomService.cs
public partial class CustomService
{
public List<Code> GetDepartment(bool activeOnly)
{
List<Code> retVal = new List<Code>();
---some code----
return retVal;
}
}
ProgramList.ascx.cs
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
List<Code> dept = new List<Code>CustomService.GetDepartment(true);
ddlDepartment.DataSource = dept;
ddlDepartment.DataBind();
}
}
//error an object reference is required for an nonstatic field, method or Property CustomService.GetDepartment(true);
you forgot to create object first and than you can call the method
another thing is you just need to assign the value directly as i did below, there is no need to create any new list
check the code below that will work for you