if i select
Select a User Group
then
Department
if there is already a user in Department then no
Designation and Sanctioned Post shown otherwise shown

if i select
Select a User Group
then
Department
if there is already a user in Department then no
Designation and Sanctioned Post shown otherwise shown

Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Vishal JoshiRank #377 · 6.7K reputationPosted Jun 11, 2024, 1:25 AM EDT
Hello
You need to use a cascading drop-down to achieve the requirement. Check out the below sample code.
onSelectUserGroup(){ $.ajax({ type: "GET", url: "/api/getDesignationUser", success: function(data) { If(data.hasUsers){ //bind data } else{ // hide drop-down } } }); } onSelectDepartment(){ $.ajax({ type: "GET", url: "/api/sanctionedPosts", success: function(data) { If(data.hasPosts){ //bind data } else{ // hide drop-down } } }); }Thanks
Vishal Joshi
Jayraj ChhayaRank #304 · 8.2K reputationPosted Jun 10, 2024, 9:13 AM EDT
In Dot Net, you can achieve this functionality by implementing cascading dropdowns or conditional visibility based on user selections. You can use JavaScript or server-side code to handle these interactions.
// Code to populate User Groups dropdown List userGroups = new List { "Group A", "Group B", "Group C" }; ddlUserGroup.DataSource = userGroups; ddlUserGroup.DataBind(); // Code to handle User Group selection change event protected void ddlUserGroup_SelectedIndexChanged(object sender, EventArgs e) { string selectedUserGroup = ddlUserGroup.SelectedValue; if (selectedUserGroup == "Select a User Group") { // Show Department dropdown divDepartment.Visible = true; // Check if users exist in the selected department if (UsersExistInDepartment(selectedDepartment)) { // Hide Designation and Sanctioned Post fields divDesignation.Visible = false; divSanctionedPost.Visible = false; } else { // Show Designation and Sanctioned Post fields divDesignation.Visible = true; divSanctionedPost.Visible = true; } } } // Function to check if users exist in the selected department private bool UsersExistInDepartment(string department) { // Logic to check if users exist in the department return true; // Return true if users exist, false otherwise }