dropdown selected index page event fires on page load

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Manikgisl
    New Member
    • Oct 2008
    • 37

    dropdown selected index page event fires on page load

    Hi,

    In my web form, i have 2 drop downlist controls. eg. dropdown1 and dropdown2. I will change the dropdownlist1 item, consequently selectedindexch anged event fires and reloads the dropdownlist2 items. And i have another button also in order to get the result based on the dropdown1 and dropdown2.

    Lets say for example, i have a list of countries in dropdown1 and a list of states in dropdown2. I selected "India" in dropdown1 and correspondingly "Tamilnadu" in dropdown2. And then click a button which calls the dataset based on dropdown1 and dropdown2.

    The problem i face here is, whenever i click on the button to load the dataset, dropdown1 value remains the same as the dataset is not called again, whereas the dropdown2 value changes to the first one as it gets called automatically during postback.

    For your information, I have loaded both the lists in the page load using (!IsPostback) property.

    My coding is as follows:
    Code:
     protected void Page_Load(object sender, EventArgs e)
        {
            try
            {
                if (Session["sesUserName"] == null)
                {
                    Response.Redirect("sessionExpr.aspx", false);
                }
                else
                {
                    lblStatus.Visible = false;
                    pnlEvaluate.Visible = false;
                    if (!IsPostBack)
                    {
                        fnLoadDropDown1();
                        fnLoadDropdown2();
                    }
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    
     public void fnLoadDropDown1()
        {
            dsLoadDD1 = objWebRef.fnLoadOnlineTest();
            if (dsLoadDD1.Tables[0].Rows.Count > 0)
            {
                ddTestTitle.DataTextField = "vchTestTitle";
                ddTestTitle.DataValueField = "intTestID";
                ddTestTitle.DataSource = dsLoadDD1.Tables[0];
                ddTestTitle.DataBind();
            }
        }
    
    public void fnLoadDropDown2()
        {
            dsLoadDD2 = objWebRef.fnLoadOnlineTest();
            if (dsLoadDD2.Tables[0].Rows.Count > 0)
            {
                ddUser.DataTextField = "vchUser";
                ddUser.DataValueField = "intUserID";
                ddUser.DataSource = dsLoadDD2.Tables[0];
                ddUser.DataBind();
            }
        }
    
    protected void ddTestTitle_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                fnLoadUsersforTest();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
    Please give me a solution for this.. Mail me @

    <email removed>

    Thanks in advance..

    Mani
    Last edited by Frinavale; Mar 26 '10, 07:43 PM. Reason: Please post code in [code] ... [/code] tags. Added code tags and removed the email address posted: violation of posting rules
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    The code that you have posted does not reflect the problem that you have posted.


    The problem i face here is, whenever i click on the button to load the dataset, dropdown1 value remains the same as the dataset is not called again, whereas the dropdown2 value changes to the first one as it gets called automatically during postback.
    Since the problem occurs in the button click event, doesn't it make sense to post the code for the button click event?

    -Frinny

    Comment

    Working...