943,522 Members | Top Members by Rank

Ad:
  • ASP.NET Discussion Thread
  • Unsolved
  • Views: 1183
  • ASP.NET RSS
Jul 6th, 2009
0

about cascading dropdown list

Expand Post »
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
ASP.NET Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
vytla is offline Offline
13 posts
since Jul 2009
Jul 7th, 2009
0

Re: about cascading dropdown list

Change page load event as below

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 165
Solved Threads: 113
Posting Pro
Ramesh S is offline Offline
580 posts
since Jun 2009
Jul 7th, 2009
0

Re: about cascading dropdown list

ASP.NET Syntax (Toggle Plain Text)
  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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
phanvv is offline Offline
3 posts
since Jul 2009
Jul 7th, 2009
0

Re: about cascading dropdown list

Ramesh S,

32nd post and you are missing code tags.


[CODE=ASP.NET]
....
....
[/CODE]
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008
Jul 7th, 2009
0

Re: about cascading dropdown list

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

ASP.NET Syntax (Toggle Plain Text)
  1. protected override void OnPreRender(EventArgs e)
  2. {
  3. base.OnPreRender(e);
  4. Department();
  5. }
Moderator
Reputation Points: 2136
Solved Threads: 1228
Posting Genius
adatapost is offline Offline
6,527 posts
since Oct 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in ASP.NET Forum Timeline: vb.net Saving Checkboxlist checked items to database
Next Thread in ASP.NET Forum Timeline: The Columns of the Grid Duplicates themselves





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC