hi every body i am using three dropdownlist for search criteria , the problem is when dropdown idex is selected the dropdown itself will disappear,because the page is getting refereshed every time when i select dropdown thwe index value will be 1. pls help me out.
i attached the code pls go through it

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            Department();
        }
        catch (TimeoutException ex)
        {
            Session.Clear();
            Response.Redirect("~/Student/Login.aspx");
        }
    }
    private void Department()
    {
        CommunityManagement.CommunityManagementSoap deptService = new CommunityManagement.CommunityManagementSoapClient();
        GetAllDepartmentRequest deptRequest = new GetAllDepartmentRequest();
        deptRequest.Body = new GetAllDepartmentRequestBody();
        GetAllDepartmentResponse deptResponse = deptService.GetAllDepartment(deptRequest);
        if (deptResponse != null)
        {


            drpDept.DataSource = deptResponse.Body.GetAllDepartmentResult;
            drpDept.DataTextField = "DepartmentName";
            drpDept.DataValueField = "DepartmentId";
            drpDept.DataBind();






        }

    }
 protected void drpDept_SelectedIndexChanged(object sender, EventArgs e)
    {
        CommunityManagement.CommunityManagementSoap branchService = new CommunityManagement.CommunityManagementSoapClient();
        GetAllBranchesByDeptIdRequest branchRequest = new GetAllBranchesByDeptIdRequest();
        branchRequest.Body = new GetAllBranchesByDeptIdRequestBody();
        branchRequest.Body.deptId = int.Parse(drpDept.SelectedItem.Value.ToString());
        GetAllBranchesByDeptIdResponse branchResponse = branchService.GetAllBranchesByDeptId(branchRequest);
        if (branchResponse != null)
        {
            drpBranch.DataSource = branchResponse.Body.GetAllBranchesByDeptIdResult;
            drpBranch.DataTextField = "BranchName";
            drpBranch.DataValueField = "BranchId";
            drpBranch.DataBind();
            //ToogleAdvacneSearch();
        }

    }
    protected void drpBranch_SelectedIndexChanged(object sender, EventArgs e)
    {
        CommunityManagement.CommunityManagementSoap classService = new CommunityManagement.CommunityManagementSoapClient();
        GetAllClassNamesRequest classRequest = new GetAllClassNamesRequest();
        classRequest.Body = new GetAllClassNamesRequestBody();
        classRequest.Body.branchId = drpBranch.SelectedItem.Value.ToString();
        GetAllClassNamesResponse classResponse = classService.GetAllClassNames(classRequest);
        if (classResponse != null)
        {
            drpClass.DataSource = classResponse.Body.GetAllClassNamesResult;
            drpClass.DataTextField = "ClassTitle";
            drpClass.DataValueField = "ClassId";
            drpClass.DataBind();
            //ToogleAdvacneSearch();

        }


    }
    protected void drpClass_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
    protected void btnSearch_Click(object sender, EventArgs e)
    {
        CommunityManagement.CommunityManagementSoap searchService = new CommunityManagement.CommunityManagementSoapClient();
        GetAllUserNamesByUserTypeRequest searchRequest = new GetAllUserNamesByUserTypeRequest();
        searchRequest.Body = new GetAllUserNamesByUserTypeRequestBody();
        searchRequest.Body.name = txtName.Text;
        searchRequest.Body.userType = int.Parse(drpUserType.SelectedItem.Value);
        searchRequest.Body.dept = drpDept.SelectedItem.Value.ToString();
        searchRequest.Body.className = drpClass.SelectedItem.Value;
      
        GetAllUserNamesByUserTypeResponse searchResponse = searchService.GetAllUserNamesByUserType(searchRequest);
        if (searchResponse != null)
        {
            lstBoxFriends.Items.Clear();
            foreach (Search search in searchResponse.Body.GetAllUserNamesByUserTypeResult)
            {
               
                    string name = search.FirstName.ToString();
                    lstBoxFriends.Items.Add(name);


              




            }

        }
    }
//here is the web services written

 [WebMethod]
    public List<StaffClasses> GetAllClassNames(string branchId)
    {
        List<StaffClasses> classList = new List<StaffClasses>();
        try
        {
            string connectionString = ConfigurationSettings.AppSettings["connectionString"];
            SqlConnection con = new SqlConnection(connectionString); con.Open();
            SqlCommand cmd = new SqlCommand("select distinct c.Title,c.Class_Id from Class_Master c,Branch_Master b where c.Branch_Id =" + branchId.ToString(), con);

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                StaffClasses className = new StaffClasses();
                className.ClassId = dr["Class_Id"].ToString();
                className.ClassTitle = dr["Title"].ToString();
                classList.Add(className);
            }

            con.Close();
        }
        catch (Exception ex)
        {
        }
        return classList;
    }

    [WebMethod]
    public List<Department> GetAllDepartment()
    {
        List<Department> deptList = new List<Department>();
        try
        {
            string connectionString = ConfigurationSettings.AppSettings["connectionString"];
            SqlConnection con = new SqlConnection(connectionString); con.Open();
            SqlCommand cmd = new SqlCommand("select * from Department_Master", con);

            SqlDataReader dr = cmd.ExecuteReader();

            while (dr.Read())
            {
                Department dept = new Department();
                dept.DepartmentId = int.Parse(dr["Department_Id"].ToString());
                dept.DepartmentName = dr["Department_Name"].ToString();
                deptList.Add(dept);
            }

            con.Close();
        }
        catch (Exception ex)
        {
        }
        return deptList;
    }

    [WebMethod]
    public List<Branches> GetAllBranchesByDeptId(int deptId)
    {
        string connectionString = ConfigurationSettings.AppSettings["connectionString"];
        SqlConnection con = new SqlConnection(connectionString);

        con.Open();
        SqlCommand cmd = new SqlCommand("select distinct b.Branch_Id,b.Branch_Name from Branch_Master b,Department_Master d where b.Department_Id =" + deptId.ToString(), con);

        SqlDataReader dr = cmd.ExecuteReader();
        List<Branches> branchtList = new List<Branches>();
        while (dr.Read())
        {
            Branches branches = new Branches();
            branches.BranchId = dr["Branch_Id"].ToString();
            branches.BranchName = dr["Branch_Name"].ToString();
            branchtList.Add(branches);
            // branches.DeptId = int.Parse(dr["Department_Id"].ToString());

        }

        con.Close();
        return branchtList;
    }

    [WebMethod]
    public List<Search> GetAllUserNamesByUserType(int userType, string name, st

Recommended Answers

All 4 Replies

Change page load event as below

protected void Page_Load(object sender, EventArgs e)
    {
        try
        {
            if (!IsPostBack)                    
              {
                 Department();
               }
        }
        catch (TimeoutException ex)
        {
            Session.Clear();
            Response.Redirect("~/Student/Login.aspx");
        }
    }
protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    Department();
}

Ramesh S,

32nd post and you are missing code tags.

[CODE=ASP.NET] .... ....

[/code]

phanvv,
Use code tags. Wrap up your source in bb code tags. Read How to use code tags?

protected override void OnPreRender(EventArgs e)
{
    base.OnPreRender(e);
    Department();
}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.