about cascading dropdown list

Please support our ASP.NET advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Reply

Join Date: Jul 2009
Posts: 13
Reputation: vytla is an unknown quantity at this point 
Solved Threads: 0
vytla vytla is offline Offline
Newbie Poster

about cascading dropdown list

 
0
  #1
Jul 6th, 2009
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
  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. Department();
  6. }
  7. catch (TimeoutException ex)
  8. {
  9. Session.Clear();
  10. Response.Redirect("~/Student/Login.aspx");
  11. }
  12. }
  13. private void Department()
  14. {
  15. CommunityManagement.CommunityManagementSoap deptService = new CommunityManagement.CommunityManagementSoapClient();
  16. GetAllDepartmentRequest deptRequest = new GetAllDepartmentRequest();
  17. deptRequest.Body = new GetAllDepartmentRequestBody();
  18. GetAllDepartmentResponse deptResponse = deptService.GetAllDepartment(deptRequest);
  19. if (deptResponse != null)
  20. {
  21.  
  22.  
  23. drpDept.DataSource = deptResponse.Body.GetAllDepartmentResult;
  24. drpDept.DataTextField = "DepartmentName";
  25. drpDept.DataValueField = "DepartmentId";
  26. drpDept.DataBind();
  27.  
  28.  
  29.  
  30.  
  31.  
  32.  
  33. }
  34.  
  35. }
  36. protected void drpDept_SelectedIndexChanged(object sender, EventArgs e)
  37. {
  38. CommunityManagement.CommunityManagementSoap branchService = new CommunityManagement.CommunityManagementSoapClient();
  39. GetAllBranchesByDeptIdRequest branchRequest = new GetAllBranchesByDeptIdRequest();
  40. branchRequest.Body = new GetAllBranchesByDeptIdRequestBody();
  41. branchRequest.Body.deptId = int.Parse(drpDept.SelectedItem.Value.ToString());
  42. GetAllBranchesByDeptIdResponse branchResponse = branchService.GetAllBranchesByDeptId(branchRequest);
  43. if (branchResponse != null)
  44. {
  45. drpBranch.DataSource = branchResponse.Body.GetAllBranchesByDeptIdResult;
  46. drpBranch.DataTextField = "BranchName";
  47. drpBranch.DataValueField = "BranchId";
  48. drpBranch.DataBind();
  49. //ToogleAdvacneSearch();
  50. }
  51.  
  52. }
  53. protected void drpBranch_SelectedIndexChanged(object sender, EventArgs e)
  54. {
  55. CommunityManagement.CommunityManagementSoap classService = new CommunityManagement.CommunityManagementSoapClient();
  56. GetAllClassNamesRequest classRequest = new GetAllClassNamesRequest();
  57. classRequest.Body = new GetAllClassNamesRequestBody();
  58. classRequest.Body.branchId = drpBranch.SelectedItem.Value.ToString();
  59. GetAllClassNamesResponse classResponse = classService.GetAllClassNames(classRequest);
  60. if (classResponse != null)
  61. {
  62. drpClass.DataSource = classResponse.Body.GetAllClassNamesResult;
  63. drpClass.DataTextField = "ClassTitle";
  64. drpClass.DataValueField = "ClassId";
  65. drpClass.DataBind();
  66. //ToogleAdvacneSearch();
  67.  
  68. }
  69.  
  70.  
  71. }
  72. protected void drpClass_SelectedIndexChanged(object sender, EventArgs e)
  73. {
  74.  
  75. }
  76. protected void btnSearch_Click(object sender, EventArgs e)
  77. {
  78. CommunityManagement.CommunityManagementSoap searchService = new CommunityManagement.CommunityManagementSoapClient();
  79. GetAllUserNamesByUserTypeRequest searchRequest = new GetAllUserNamesByUserTypeRequest();
  80. searchRequest.Body = new GetAllUserNamesByUserTypeRequestBody();
  81. searchRequest.Body.name = txtName.Text;
  82. searchRequest.Body.userType = int.Parse(drpUserType.SelectedItem.Value);
  83. searchRequest.Body.dept = drpDept.SelectedItem.Value.ToString();
  84. searchRequest.Body.className = drpClass.SelectedItem.Value;
  85.  
  86. GetAllUserNamesByUserTypeResponse searchResponse = searchService.GetAllUserNamesByUserType(searchRequest);
  87. if (searchResponse != null)
  88. {
  89. lstBoxFriends.Items.Clear();
  90. foreach (Search search in searchResponse.Body.GetAllUserNamesByUserTypeResult)
  91. {
  92.  
  93. string name = search.FirstName.ToString();
  94. lstBoxFriends.Items.Add(name);
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102. }
  103.  
  104. }
  105. }
  106. //here is the web services written
  107.  
  108. [WebMethod]
  109. public List<StaffClasses> GetAllClassNames(string branchId)
  110. {
  111. List<StaffClasses> classList = new List<StaffClasses>();
  112. try
  113. {
  114. string connectionString = ConfigurationSettings.AppSettings["connectionString"];
  115. SqlConnection con = new SqlConnection(connectionString); con.Open();
  116. 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);
  117.  
  118. SqlDataReader dr = cmd.ExecuteReader();
  119.  
  120. while (dr.Read())
  121. {
  122. StaffClasses className = new StaffClasses();
  123. className.ClassId = dr["Class_Id"].ToString();
  124. className.ClassTitle = dr["Title"].ToString();
  125. classList.Add(className);
  126. }
  127.  
  128. con.Close();
  129. }
  130. catch (Exception ex)
  131. {
  132. }
  133. return classList;
  134. }
  135.  
  136. [WebMethod]
  137. public List<Department> GetAllDepartment()
  138. {
  139. List<Department> deptList = new List<Department>();
  140. try
  141. {
  142. string connectionString = ConfigurationSettings.AppSettings["connectionString"];
  143. SqlConnection con = new SqlConnection(connectionString); con.Open();
  144. SqlCommand cmd = new SqlCommand("select * from Department_Master", con);
  145.  
  146. SqlDataReader dr = cmd.ExecuteReader();
  147.  
  148. while (dr.Read())
  149. {
  150. Department dept = new Department();
  151. dept.DepartmentId = int.Parse(dr["Department_Id"].ToString());
  152. dept.DepartmentName = dr["Department_Name"].ToString();
  153. deptList.Add(dept);
  154. }
  155.  
  156. con.Close();
  157. }
  158. catch (Exception ex)
  159. {
  160. }
  161. return deptList;
  162. }
  163.  
  164. [WebMethod]
  165. public List<Branches> GetAllBranchesByDeptId(int deptId)
  166. {
  167. string connectionString = ConfigurationSettings.AppSettings["connectionString"];
  168. SqlConnection con = new SqlConnection(connectionString);
  169.  
  170. con.Open();
  171. 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);
  172.  
  173. SqlDataReader dr = cmd.ExecuteReader();
  174. List<Branches> branchtList = new List<Branches>();
  175. while (dr.Read())
  176. {
  177. Branches branches = new Branches();
  178. branches.BranchId = dr["Branch_Id"].ToString();
  179. branches.BranchName = dr["Branch_Name"].ToString();
  180. branchtList.Add(branches);
  181. // branches.DeptId = int.Parse(dr["Department_Id"].ToString());
  182.  
  183. }
  184.  
  185. con.Close();
  186. return branchtList;
  187. }
  188.  
  189. [WebMethod]
  190. 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
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 404
Reputation: Ramesh S will become famous soon enough Ramesh S will become famous soon enough 
Solved Threads: 79
Ramesh S Ramesh S is offline Offline
Posting Pro in Training

Re: about cascading dropdown list

 
0
  #2
Jul 7th, 2009
Change page load event as below

  1. protected void Page_Load(object sender, EventArgs e)
  2. {
  3. try
  4. {
  5. if (!IsPostBack)
  6. {
  7. Department();
  8. }
  9. }
  10. catch (TimeoutException ex)
  11. {
  12. Session.Clear();
  13. Response.Redirect("~/Student/Login.aspx");
  14. }
  15. }
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.
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 3
Reputation: phanvv is an unknown quantity at this point 
Solved Threads: 0
phanvv's Avatar
phanvv phanvv is offline Offline
Newbie Poster

Re: about cascading dropdown list

 
0
  #3
Jul 7th, 2009
  1. protected override void OnPreRender(EventArgs e)
  2. {
  3. base.OnPreRender(e);
  4. Department();
  5. }
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
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,420
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 430
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: about cascading dropdown list

 
0
  #4
Jul 7th, 2009
Ramesh S,

32nd post and you are missing code tags.


[CODE=ASP.NET]
....
....
[/CODE]
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,420
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 430
adatapost's Avatar
adatapost adatapost is offline Offline
Nearly a Posting Maven

Re: about cascading dropdown list

 
0
  #5
Jul 7th, 2009
phanvv,
Use code tags. Wrap up your source in bb code tags. Read How to use code tags?

  1. protected override void OnPreRender(EventArgs e)
  2. {
  3. base.OnPreRender(e);
  4. Department();
  5. }
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC