Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have created a user control where in there is dropdownlist. To bind dropdownlist I have passed Generic List object to a method.

C#
public void BindDropDownList<T>(List<T> data, string val, string txt)
        {
            foreach (var v in data)
            {

            }
        }



and called this method like below.

C#
msc_accounthead.BindDropDownList<AccountHead>(acc_list, "ahmID", "ahmHead");


for reference Click Here

How can I access properties(highlighted by green) to bind a drpdownlist?
Posted

1 solution

I don't think you ned to loop. Below should work.
C#
ddlDropdownId.DataSource = data;
ddlDropdownId.DataTextField = txt;
ddlDropdownId.DataValueField = val;
ddlDropdownId.DataBind();
 
Share this answer
 
v2
Comments
raju@shekhar 2-May-15 9:25am    
Thanks Tadit
Most welcome Raju. :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900