Problem in using Dropdownlist

I have a dropdownlistFN control for flat_no in which value is fetched from the database, and as i select a value from the list and click on primary member button , the data shown corresponding to the selected value is always for the first flat no which appears 1st in the list on page load , but not for the one which is selected..

kindly help me...
edit_member.aspx
edit_member.aspx.cs
Pdetails.aspx
Pdetails.aspx.cs
Sukesh ShuklaAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Lokesh B RDeveloperCommented:
Hi,

Change as below and try.

protected void Page_Load(object sender, EventArgs e)
        {
if (!IsPostBack)
            {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
            SqlDataAdapter da = new SqlDataAdapter("Select Flat from Primary_Member", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
           DropDownListFN.DataSource = dt;
           DropDownListFN.DataTextField = "Flat";
            DataBind();
}
  }

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Prakash SamariyaIT ProfessionalCommented:
Please try with "SelectedItem.Text"/"SelectedItem.Value" or "SelectedValue" property instead DropdownList.Text?

Also check whether values comes correctly using debug in code behind
Lokesh B RDeveloperCommented:
 protected void Page_Load(object sender, EventArgs e)
        {
if (!IsPostBack)
            {
            SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["HousingConnectionString"].ConnectionString);
            SqlDataAdapter da = new SqlDataAdapter("Select Flat from Primary_Member", conn);
            DataTable dt = new DataTable();
            da.Fill(dt);
           DropDownListFN.DataSource = dt;
           DropDownListFN.DataTextField = "Flat";
            DataBind();
}
        }

        protected void Button1_Click(object sender, EventArgs e)
        {

            Response.Redirect("Pdetails.aspx?fnum=" + DropDownListFN.SelectedItem.Text);
        }

        protected void Button2_Click(object sender, EventArgs e)
        {
            Response.Redirect("Fdetails1.aspx?fnum=" + DropDownListFN.SelectedItem.Text);
        }

Open in new window

Angular Fundamentals

Learn the fundamentals of Angular 2, a JavaScript framework for developing dynamic single page applications.

Sukesh ShuklaAuthor Commented:
On changing it to :

 Response.Redirect("Pdetails.aspx?fnum=" + DropDownListFN.SelectedItem.Text);

Still the same thing is happening
Prakash SamariyaIT ProfessionalCommented:
I think it's because on page load you refresh the list, so selected value got disappear!

Please apply IsPostBack condition in page load to avoid refreshing the list again on everytime!

Have you tried Lokesh's First Comment [ID: 41133585]?

Please try that and let us know if it works or not!
Sukesh ShuklaAuthor Commented:
Thank you Lokesh And Prakash........
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.