Link to home
Start Free TrialLog in
Avatar of Sukesh Shukla
Sukesh Shukla

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Lokesh B R
Lokesh B R
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Please try with "SelectedItem.Text"/"SelectedItem.Value" or "SelectedValue" property instead DropdownList.Text?

Also check whether values comes correctly using debug in code behind
 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

Avatar of Sukesh Shukla
Sukesh Shukla

ASKER

On changing it to :

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

Still the same thing is happening
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!
Thank you Lokesh And Prakash........