Hi
I am getting error after writing below code - Syntax error ',' expected. The name address1,address2 does not exists in the current context.
htmlTable.Append("");
htmlTable.Append("");
string deleteAttributes = Status == "Blocked" ? "style='pointer-events: none; opacity: 0.5;' onclick='return false;'" : "data-toggle='modal' data-target='#modal_Delete' ";
htmlTable.Append($"");
htmlTable.Append(" ");
htmlTable.Append("");
htmlTable.Append("");
Count++;
}
htmlTable.Append("");
htmlTable.Append("");
PlaceHolderTable.Controls.Add(new Literal { Text = htmlTable.ToString() });
Thanks
Naimish MakwanaPosted Aug 30, 2024, 6:19 AM
It looks like there are a couple of issues in your code. The error message suggests that there might be a syntax error and that the variables
address1andaddress2are not recognized in the current context. Here are a few things to check and correct:Syntax Error: Ensure that the double quotes inside the string are properly escaped. You can use
@to create a verbatim string literal to avoid escaping issues.Variable Context: Make sure that
row["address1"]androw["address2"]are accessible in the current context. If they are not, you might need to pass them correctly.Here’s a revised version of your code:
This should resolve the syntax error and ensure that the variables are correctly referenced. If the issue persists, double-check that
row["address1"]androw["address2"]are correctly populated and accessible in the current context.Thanks
Sriyans SharmaPosted Aug 30, 2024, 9:22 AM
Fixing string interpolation inside
Appendmethod:"{row["address1"]}", which should be a string interpolation inside a C# string.$"{row["address1"]}"instead.Ensuring the loop context:
Closing the loop properly:
Here’s the corrected code:
Key Corrections:$for string interpolation in C#.rowsin the example).If your loop context is different, make sure to adjust it accordingly.