Introduction:
In this article i will explain how to bind DropDownList using simple user defined method in ASP.Net.
Objective:
- Bind DropDownList using simple user defined method in ASP.Net
- User defined method should accept collection (e.g: List<Student> or List<Department> or List<User> or List<Role> etc)
- User defined method should accept DataTable as well.
In this article i created a class called Student.cs
as shown below:
I created a class called Deptment.cs
as shown below:
DropDownListDemo.aspx:-
DropDownListDemo.aspx.cs:-
FillDropDown method accepts 4 parameters:
- dropDownList - DropDownList ID for which you are binding
- list - It may be List<Student> or List<Department>, List<User>, List<Role>, etc.
- dataTextField - Gets or sets the field of the data source that provides the text content of the list items.
- dataValueField - Gets or sets the field of the data source that provides the value of each list item
Output:-
No comments:
Post a Comment