Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have two dropdown list in one page.
when i select one value from first dropdown,value in second dropdown comes according to selected value in first dropdown.
But problem is ,when i click on submit button ,if i have select anything from second dropdown,it takes first value and insert it. this is somthing like..page load problem when i click on submit.
but i cant understand what is actually problem.
here is my code.
first dropdown is set to autopostback=true.
C#
int Userid;

objdal.Deptid = Convert.ToInt16(ddlName.SelectedValue);
objdal.Name = ddlName.SelectedItem.Text;
                
dv = objdal.AssignTimetable_SelectDeptid(); //select userid from userinfo where deptid=@deptid AND name=@name
Userid = Convert.ToInt16(dv.Table.Rows[0]["Userid"].ToString());


here userid is always comming of first value from second dropdown.
Posted
v2
Comments
Avik Ghosh22 12-Feb-13 2:18am    
IN PAGELOAD IF(!ISPOSRBACK)
{
}
TRY THIS.
Member 9511889 12-Feb-13 2:25am    
i have already doing this in my code.
Karthik Harve 12-Feb-13 2:29am    
did you checked, are there any duplicate user IDs ?

1 solution

C#
protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            SqlDataAdapter ad = new SqlDataAdapter("select Fname,id from x",con);
            DataTable dt = new DataTable();
            ad.Fill(dt);
            if(dt.Rows.Count>0)
            {
                uxCountry.DataSource=dt;
                uxCountry.DataTextField = "Fname";
                uxCountry.DataTextField = "id";
                uxCountry.DataBind();
            }
        }
    }
    protected void uxCountry_SelectedIndexChanged(object sender, EventArgs e)
    {
        uxStates.Items.Clear();
        SqlDataAdapter ad = new SqlDataAdapter("select Lname,yid from y where xid=" + uxCountry.Items[uxCountry.SelectedIndex].Value, con);
         DataTable dt = new DataTable();
        ad.Fill(dt);
        if (dt.Rows.Count > 0)
        {
            uxStates.DataSource = dt;
            uxStates.DataTextField = "Lname";
            uxStates.DataTextField = "yid";
            uxStates.DataBind();
        }
    }


I tried this to filled the two dropdown Country and its states,it works well for me while postback on submit.
 
Share this answer
 
v2

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