Hi
In below code i want if Status = "Disabled" then Delete shoud be greyed
C#
htmlTable.Append(" ");Thanks
Hi
In below code i want if Status = "Disabled" then Delete shoud be greyed
htmlTable.Append(" ");Thanks
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
Gowtham CpRank #1,552 · 1K reputationPosted Aug 23, 2024, 1:23 AM EDT
To gray out the "Delete" button when the status is "Disabled," you can adjust your code like this:
// Set the status (replace with your actual status variable) string status = "Disabled"; // Change this based on your logic // Build the table cell htmlTable.Append(""); // Add the Edit button htmlTable.Append(""); // Conditionally add the Delete button string deleteClass = status == "Disabled" ? "text-muted" : "text-danger-600"; string deleteAttributes = status == "Disabled" ? "disabled" : ""; htmlTable.Append($""); htmlTable.Append("");This makes your UI cleaner and more intuitive! Hope it helps!
Aman GuptaRank #193 · 12.4K reputationPosted Aug 24, 2024, 5:20 AM EDT
Hi Ramco,
To conditionally grey out the delete icon based on the
Statusvalue in your HTML, you need to dynamically modify the HTML string based on theStatusvalue. Here's how you can achieve this in C#.C# Code Example
// Assuming 'status' is a variable holding the value of the Status field string status = "Disabled"; // Replace with your actual status variable // Initialize StringBuilder to construct the HTML table row var htmlTable = new StringBuilder(); htmlTable.Append(""); htmlTable.Append(""); htmlTable.Append(""); // Check if status is 'Disabled' if (status == "Disabled") { htmlTable.Append(""); } else { htmlTable.Append(""); } htmlTable.Append("");-
- The
-
- If
- Uses the class
- Includes
- Uses
-
- If the status is not "Disabled", the delete icon retains its normal appearance and functionality.
CSS Classes:Check Status:
ifstatement checks if thestatusis "Disabled".Greying Out the Delete Icon:
statusis "Disabled", the delete icontag:text-secondary-600to apply a grey color.style='pointer-events: none;'to make it non-clickable.onclick='return false;'to prevent any actions if clicked.Default Case:
Ensure you have the necessary CSS classes defined to reflect the grey color for disabled state. For example:
.text-secondary-600 { color: #6c757d; /* Grey color */ opacity: 0.6; /* Optional: visually indicate disabled state */ }This code dynamically generates HTML based on the
statusvalue, allowing you to conditionally format the delete icon in your table rows.