This is drop down list how to bind in asp.net using C sharp and just create object then pass that drop down id. see the following code step by step.
Step:1

Just create a HTML code like this and then SkinID its not important.

<table><tr><td>  <asp:DropDownList ID="ddlAddCompanyUser" runat="server" SkinID="dropdownlist_large"
                                AutoPostBack="true" OnSelectedIndexChanged="ddlAddCompanyUser_SelectedIndexChanged">
                            </asp:DropDownList></td></tr></table>
Step:2

This code write back end like this and pass the drop down list id and then if u want the selected value for some further process. just write a OnSelectedIndexChanged get the values. then just the pass the method name in OnLoad_page(){LoadAddCompanyUser()}
private void LoadAddCompanyUser()
    {
        List<Company> objCompanyList = Company.GetAllCompany(); // Company table object
        objCompanyList = objCompanyList.OrderBy(c => c.CompanyName).ToList();
        
        ddlAddCompanyUser.Items.Clear();
        ddlAddCompanyUser.DataSource = objCompanyList;
        Utility.BindDropDownList(ddlAddCompanyUser, "CompanyName", "CompanyID", "-------- Select Company -------");
    }
Step:3
Its using for get the value while the select value.
protected void ddlAddCompanyUser_SelectedIndexChanged(object sender, EventArgs e)
    {
  string CompanyName=(ddlAddCompanyUser.SelectedItem.Value));
    }

0 comments

Related Posts Plugin for WordPress, Blogger...