| | |
about cascading dropdown list
Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
![]() |
•
•
Join Date: Jul 2009
Posts: 13
Reputation:
Solved Threads: 0
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
i attached the code pls go through it
ASP.NET Syntax (Toggle Plain Text)
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
Last edited by Ancient Dragon; Jul 6th, 2009 at 9:11 am. Reason: add code tags
•
•
Join Date: Jun 2009
Posts: 404
Reputation:
Solved Threads: 79
Change page load event as below
ASP.NET Syntax (Toggle Plain Text)
protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { Department(); } } catch (TimeoutException ex) { Session.Clear(); Response.Redirect("~/Student/Login.aspx"); } }
Last edited by Ezzaral; Jul 7th, 2009 at 12:17 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
ASP.NET Syntax (Toggle Plain Text)
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Department(); }
Last edited by Ezzaral; Jul 7th, 2009 at 12:18 pm. Reason: Added [code] [/code] tags. Please use them to format any code that you post.
Vu Van Phan
Ministry of Science and Technology
Skype: phanvv_hd
Ministry of Science and Technology
Skype: phanvv_hd
phanvv,
Use code tags. Wrap up your source in bb code tags. Read How to use code tags?
Use code tags. Wrap up your source in bb code tags. Read How to use code tags?
ASP.NET Syntax (Toggle Plain Text)
protected override void OnPreRender(EventArgs e) { base.OnPreRender(e); Department(); }
Failure is not fatal, but failure to change might be. - John Wooden
![]() |
Similar Threads
- Cascading Dropdown list with (AJAX, PHP) (PHP)
- DropDown List (VB.NET)
- Feeding a value in a dropdown list to another dropdown list (PHP)
Other Threads in the ASP.NET Forum
- Previous Thread: vb.net Saving Checkboxlist checked items to database
- Next Thread: The Columns of the Grid Duplicates themselves
| Thread Tools | Search this Thread |
.net 2.0 activexcontrol advice ajax alltypeofvideos asp asp.net bc30451 beginner bottomasp.net browser c# c#gridviewcolumn cac checkbox class commonfunctions compatible confirmationcodegeneration content contenttype countryselector courier dataaccesslayer database datagridview datagridviewcheckbox datalist deployment development dgv dropdownlist dynamic dynamically edit embeddingactivexcontrol fileuploader fill findcontrol flash flv formatdecimal forms formview gridview gudi homeedition iframe iis javascript jquery listbox microsoft mouse mssql multistepregistration news objects opera panelmasterpagebuttoncontrols problem redirect registration relationaldatabases reportemail rotatepage schoolproject security serializesmo.table sessionvariables silverlight smartcard smoobjects software sql sql-server sqlserver2005 ssl textbox tracking treeview unauthorized validatedate validation vb.net video videos virtualdirectory vista visual-studio visualstudio web webapplications webarchitecture webdevelopemnt webdevelopment webprogramming webservice youareanotmemberofthedebuggerusers






