Click here to Skip to main content
15,896,606 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello,
Need help in dropdownlist selectedindex not changing situation.
In my asp.net page, I have four dropdownlists.Only the first one can be bound in pageload event (in if(!ispostback) condition).All the others are loaded only after the first dropdownlist value selected.
My problem is that the fourth dropdownlist selectedindex not changing which will bound data after the selection of third dropdownlist.

I feel this as a strange problem.

Sarath.

Sir I have tried this, but didnt solve. In 4th dropdownlist, every time selectedindex is 1 after postback, even after we change selection. viewstate is set true.


C#
protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
        cf.Load_Dropdown(Drp_Mix, " SELECT cm.Mix_ID, cm.Mix_Name FROM CP_Mix cm ORDER BY cm.Mix_Name ", "Mix_Name", "Mix_ID");
    }
}
protected void Drp_Mix_SelectedIndexChanged(object sender, EventArgs e)
    {
         cf.Load_Dropdown(Drp_Sale_product, " SELECT distinct  cast(gpm.N_Prd_Id AS INT) AS N_Prd_Id, gpm.V_Prd_Name,V_Prd_Name+'--'+CAST(isnull(F_Prd_Tpi_Single,'') AS VARCHAR(50))+'--'+ CAST(isnull(F_Prd_Tpi_Double,'') AS VARCHAR(50)) +'--'+CAST(cast(gpm.N_Prd_Id AS INT) AS VARCHAR(30)) AS prd  " +
                                               " FROM ProductMst gpm   where gpm.V_Prd_Name LIKE '%" + Drp_Mix.SelectedItem.Text + "%' AND  cast(gpm.N_Prd_Id AS INT) > 199999 AND V_Prd_Del_Flg='N'  ORDER BY gpm.V_Prd_Name", "prd", "N_Prd_Id");
    }

protected void Drp_Sale_product_SelectedIndexChanged(object sender, EventArgs e)
    {
    Drp_Purch.Items.Clear();
            cf.Load_Dropdown(Drp_Purch, "  SELECT distinct Comp_Prd_Id,Comp_Material FROM Components gc WHERE Comp_Prd_Id='" + Drp_Sale_product.SelectedItem.Value + "'AND Comp_Material!='" + Drp_Sale_product.SelectedItem.Value + "' ", "Comp_Material", "Comp_Prd_Id");
            Drp_Purch.Items.Insert(0, "--SELECT--");
    }
//Problem in this section
 protected void Drp_Purch_SelectedIndexChanged(object sender, EventArgs e)
    {
    string s=Drp_Purch.SelectedIndex.ToString();
    }
//selectedindex always getting  1
Posted
Updated 6-Jan-11 18:58pm
v3
Comments
Sandeep Mewara 7-Jan-11 0:49am    
Share the code with us.
Vipin Kumar Mallaya G 7-Jan-11 3:02am    
Are you handiliing prerender event and added any code in it???

Dear Friend
Please set the autopostback property of the dropdownlist to true in the aspx page not using design window
This will solve the issue in most cases

Regards
vipin Kumar Mallaya
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 7-Jan-11 0:30am    
That's right - my 5.
sarathpa 7-Jan-11 0:39am    
Sir
I have tried this, but didnt solve. In 4th dropdownlist, every time selectedindex is 1 after postback, even after we change selection.
viewstate is set true.
Dalek Dave 8-Jan-11 5:19am    
Good Call!
Hi Sarathpa,

Check for dropdownlist selectedvalues. If values are same for index 1 and 4 then even after select 4th from list it will select 1st.

Regards
Sushma
 
Share this answer
 
Comments
sarathpa 7-Jan-11 1:35am    
thanks sushma...It worked for me. Value field was same for the dropdownlist.
Sandeep Mewara 7-Jan-11 1:51am    
Nice catch! 5!
Dalek Dave 8-Jan-11 5:20am    
Good answer, 5.
Saily 11-Feb-14 14:25pm    
Banging my head for an hour. Thanks. my selectedvalues are same for all items.
ngamitiennu1990 3-Jun-14 4:22am    
Thanks Sushma. Good answer, 5
give the aspx page in dropdownlist control in below code..



<asp:dropdownlist....... xmlns:asp="#unknown">
AutoPostBack=true;</asp:dropdownlist.......>
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900