The error you're encountering is likely due to the fact that the field "MediuMunca" doesn't exist in the DataRowView for some of the queries bound to the DataList.
When you try to access a field that doesn't exist in the DataRowView, it throws an exception. To handle this situation, you're on the right track with the use of the ternary operator to check for null or DBNull.Value. However, the issue might be arising because the column "MediuMunca" is not present in all the DataRows from different queries.
To mitigate this issue, you can modify the binding logic in the following way:
<div class="row no-gutters">
<asp:TextBox ID="txtMediuMunca" class="form-control form-control-sm"
Style="font-size: 12px; color: black; resize: none; font-weight: 500;" runat="server" TextMode="MultiLine" Rows="10"
ClientIDMode="Static" Text='<%# CheckNull(Eval("MediuMunca")) %>' />
</div>
In your code-behind or in the code-behind file associated with your ASP.NET page, define the CheckNull method:
protected string CheckNull(object value)
{
if (value == null || value == DBNull.Value || string.IsNullOrWhiteSpace(value.ToString()))
{
return "-";
}
return value.ToString();
}
This CheckNull method checks whether the value is null, DBNull.Value, or an empty string and replaces it with a dash ("-") in those cases. This should prevent the "does not contain a property" error from occurring when the "MediuMunca" field is not present in certain DataRows.
Make sure to modify this method according to the exact logic you need for handling DBNull and null values in your application.
Additionally, ensure that the field "MediuMunca" is available in the DataRows from all the queries you're binding to the DataList. If it's not present in some queries, you may need to modify your SQL queries or adjust your data retrieval logic to ensure consistency in the fields across all DataRows.