Avatar of Wade Knox
Wade Knox
Flag for United States of America asked on

how to add a bound dropdownlist in asp.net formview insertitemtemplate using C#

I am using visual studio 2008 express

I am using an access database

I have a form view control which has a datasource of a "business object"

How do I make it so that the "company name" field in my webform has a dropdown list of company names to choose from when a user tries to add a new record?

The Company Name field is in the Company Table of the crm.mdb access DB

The ID is available on the page it is just hidden.

SEE PIC
pic-web.JPG
ASP.NETC#Web Applications

Avatar of undefined
Last Comment
Wade Knox

8/22/2022 - Mon
Roshan Davis

vora_bhaumik

Wade Knox

ASKER
thanks for your quick answers but:

Please do not provide links to examples as i have explored many of the google results with no avail. I am looking for a straight forward answer for my specific situation.

Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
vora_bhaumik

<asp:DropDownList ID="ddlCompany" runat="server" >
                            </asp:DropDownList>

protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            SqlConnection datacon = new SqlConnection(ConfigurationManager.ConnectionStrings["MyLink"].ConnectionString);
            datacon.Open();
            SqlCommand datacmd = new SqlCommand("usp_SelectAllDepartment",datacon);
            datacmd.CommandType = CommandType.StoredProcedure;
           
           
            DataSet ds = new DataSet();

            SqlDataAdapter adpt = new SqlDataAdapter(datacmd);
           
            adpt.Fill(ds);
                                   
            ddlCompany.DataSource = ds;
            ddlCompany.DataTextField = "CompanyName";
            ddlCompany.DataValueField = "CompanyId";
            ddlCompany.DataBind();
           
            datacon.Close();
        }


    }
      
vora_bhaumik

<asp:DropDownList ID="DropDownList1" runat="server">
</asp:DropDownList>

protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
        {
Populate1();
}
}

public void Populate1()
{

       
         OleDbConnection DBConn = default(OleDbConnection);
       
         OleDbDataAdapter DBCommand = default(OleDbDataAdapter);
       
         DataSet DSPageData = new DataSet();
       
         DBConn = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;" + "DATA SOURCE=" + Server.MapPath("db1.mdb;"));
       
         DBCommand = new OleDbDataAdapter("SELECT CompanyId, CompanyName From Company  Order By CompanyName", DBConn);
       
         DBCommand.Fill(DSPageData, "Company");
       
         DropDownList1.DataSource = DSPageData.Tables("Company").DefaultView;
       
           
         DropDownList1.DataBind();
       
     }
}
Roshan Davis

I think the link which I've provided gives the straight comment on the problem that you are facing.
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
Wade Knox

ASKER
roshmon the example you provided is using VB and I need a c# solution.

Thanks
ASKER CERTIFIED SOLUTION
Roshan Davis

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Wade Knox

ASKER
Roshmon I dont need a standard list items solution I need it to be bound to a table in my access DB.

Thanks for your effort and sorry bfor being so confusing.
Wade Knox

ASKER
I guess I need to insert and record creation date to be automatically generated also.
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
Wade Knox

ASKER
any other suggestions are greatly appreciated!