- The namespace to be used is System.Web.UI.WebControls
- The asp tag to be used is asp:DropdownList id="ddl1" runat="server" DataValueField="Id" DataTextField="Name" AutoPostBack="true" OnSelectedIndexChanged="ddl1_SelectedIndexChanged" , here datatextfield is used for the data to be displayed in the dropdownlist after loading datavaluefield is used for back end identifying the values displayed in the dropdownlist and onselectedindexchanged is an event which will be fired when a user selects an item in the list.
- In Class (aspx.cs)
protected void ddl1_SelectedIndexChanged(object sender, EventArgs e)
{
int ID = Convert.ToInt32(ddlCName.SelectedValue);
CountryDao countryDao = new CountryDao();
lvSearchMints.DataSource = countryDao.GetMint(ID);
lvSearchMints.DataBind();
}
- In .aspx page
protected void Page_Load(object sender, EventArgs e)
{
Page.DataBind();
InitializeData();
}
private void InitializeData()
{
if (!IsPostBack)
{
ddl1.DataSource = mysource;
ddl1.AppendDataBoundItems = true;
ddl1.Items.Add("Default value to be display");
ddl1.DataBind();
}
}
No comments:
Post a Comment