Hi
I have below code . I want if there is no record then in placeholder or something like that it should display "No Recourd Found".
C#
StringBuilder htmlTable = new StringBuilder();
htmlTable.Append("");
htmlTable.Append("Sr.NameStatusAction");
htmlTable.Append("");
foreach (DataRow row in dt.Rows)
{
String Status = "Blocked";
if (Convert.ToBoolean(row["status"]))
{
Status = "Active";
}
htmlTable.Append("");
htmlTable.Append("" + Count.ToString() + "");
htmlTable.Append("" + row["description"] + "");
htmlTable.Append("" + row["status"] + "");
htmlTable.Append("");
Count++;
}
htmlTable.Append("");
htmlTable.Append("");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });Thanks

Jithu ThomasRank #437 · 5.7K reputationPosted Aug 25, 2024, 5:33 AM EDT
To display "No Record Found" when there are no records in your DataTable (
dt), you can check ifdt.Rows.Countis zero before building the table. If there are no rows, you can add a message to the placeholder instead. Here's how you can modify your code to include this check:StringBuilder htmlTable = new StringBuilder(); htmlTable.Append(""); htmlTable.Append("Sr.NameStatusAction"); htmlTable.Append(""); if (dt.Rows.Count == 0) { // No records found htmlTable.Append("No Record Found"); } else { int Count = 1; foreach (DataRow row in dt.Rows) { String Status = "Blocked"; if (Convert.ToBoolean(row["status"])) { Status = "Active"; } htmlTable.Append(""); htmlTable.Append("" + Count.ToString() + ""); htmlTable.Append("" + row["description"] + ""); htmlTable.Append("" + Status + ""); htmlTable.Append("" + row["status"] + ""); htmlTable.Append(""); Count++; } } htmlTable.Append(""); htmlTable.Append(""); PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });