tags:

views:

33

answers:

1

I have a list and I am trying to add the data to the ddl. It returns data, (namespace.List). But there is something I am missing... any suggestions?

public List<getBranch> Branch { get; private set; }
...                           
getBranch(user.code);
ddlOption.DataSource = Branch;                        
ddlOption.DataBind();
+5  A: 

All you're missing is to tell the dropdown what property of getBranch to show as text and what to use as value:

ddlOption.DataTextField = "propertyOfgetBranchToShowAsText";
ddlOption.DataValueField = "propertyOfgetBranchToUseAsValue";

ok, here's how the code should look like (i think):

your Branch class properties:

public int BranchValue {get;set;}
public string BranchText {get;set;}

...

public List<Branch> branchesToShow { get; private set; }
...                           
branchesToShow = getBranch(user.code); //get the list of branches
ddlOption.DataTextField = "BranchText"
ddlOption.DataValueField = "BranchValue";
ddlOption.DataSource = branchesToShow;                        
ddlOption.DataBind();
roman m
My error now says getBranch does not contain a proterty with the name 'branchNum'
is getBranch the name of class? see my code as i think i put the Branch where it belongs
roman m