954,174 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Populate DropDown from database

I've got a DropDown which I populate from a database. When an item is selected I want to redirect to another page with the selected id, but the problem is it passes "1" no matter what was selected.

protected void Page_Load(object sender, EventArgs e)
    {
        Populate();
    }

    public void Populate()
    {
        OleDbConnection con = new OleDbConnection(
           "Provider=Microsoft.Jet.OLEDB.4.0; " +
           "Data Source=" + Server.MapPath("connect.mdb"));

        con.Open();

        string strQuery = "SELECT A_ID, Title_eng FROM C_about";
        OleDbCommand cmd = new OleDbCommand(strQuery, con);
        OleDbDataReader reader = cmd.ExecuteReader();

        titleSelection.DataSource = reader;
        titleSelection.DataValueField = "A_ID";
        titleSelection.DataTextField = "Title_eng";
        titleSelection.DataBind();

        con.Close();
        con.Dispose();
    }

    protected void titleSelection_SelectedIndexChanged(object sender, EventArgs e)
    {
        string A_ID = titleSelection.SelectedValue.ToString();

        Response.Redirect("aboutEdit.aspx?A_ID=" + A_ID);
    }


this is the view source:
Title:
WHO WE AREWHAT WE DOPermanent PlacementsTemporary staffTraining & DevelopmentCV Writing TipsJobs Titles & DescriptionsLooking for Talent?Looking for a JobRegister

jellybeannn
Junior Poster
108 posts since Mar 2010
Reputation Points: 6
Solved Threads: 0
 

Hello jellybeannn,
I guess you have to add to Page_Load event couple strings:

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


It should help you.

Rogachev
Light Poster
44 posts since Nov 2008
Reputation Points: 11
Solved Threads: 9
 

Thanks man, it solved it.

jellybeannn
Junior Poster
108 posts since Mar 2010
Reputation Points: 6
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You