To display the data into the drop down we need to bind the data into Dropdown, data collection might be in the form of Datatable, Dataset, Datareader, Disctionay or List object.
Binding data in drop of list object; Create a class to bind the objects;
it is having two property
@Binding data into dropdown
Inserting the records into list collection and bind it to dropdow
@Calling method into page load
@HTML code;
Declaring the dropdown list with blank with no items;
@How it display in browser
Binding data in drop of list object; Create a class to bind the objects;
it is having two property
public class location
{
public int id { get; set; }
public string
locationName { get; set;
}
}
private void
BindDropdown()
{ List objCLocation = new List();
objCLocation.Add(new location { id = 1,
locationName = "India" });
objCLocation.Add(new location { id = 2,
locationName = "US" });
objCLocation.Add(new location { id = 3,
locationName = "UK" });
ddlLocation.DataSource = objCLocation;
ddlLocation.DataValueField = "id";
ddlLocation.DataTextField = "locationName";
ddlLocation.DataBind();
}
@Calling method into page load
protected void Page_Load(object sender, EventArgs e)
{
BindDropdown();
}
No comments:
Post a Comment