【发布时间】:2016-04-25 07:02:08
【问题描述】:
我有一个表格,其中包含我通过按钮单击事件显示/隐藏的行。我想使用 string.IsNullOrEmpty 和 IsDateEmpty 的单元格索引检查所有可见行。 如何做到这一点?
以下代码(用于检查可见单元[0] TextBox)不起作用:
var allVisibleRows = myTbl.Rows.Cast<TableRow>().Where(row => row.Visible);
bool anyTextBoxEmpty = allVisibleRows.Any(row => string.IsNullOrEmpty(((TextBox)row.Cells[0].Controls[0]).Text));
//DestinavionValidation
if (anyTextBoxEmpty)
{
return "Please, insert a TEXT";
}
以下代码(用于检查第二个 Cell 1 DateTimeControl)不起作用:
bool anyDateTimeOneValid = allVisibleRows.Any(row => !(((DateTimeControl)row.Cells[1].Controls[0])).IsValid);
bool anyDateTimeOneEmpty = allVisibleRows.Any(row => (((DateTimeControl)row.Cells[1].Controls[0])).IsDateEmpty);
//Date Validation
if (anyDateTimeOneValid || anyDateTimeOneEmpty)
{
return "Please, insert a Date!";
}
这是以下错误
System.ArgumentOutOfRangeException:指定的参数超出了有效值的范围。参数名称: System.Web.UI.ControlCollection.get_Item(Int32 index) at Lirex.WayBillModule.b__2f(TableRow row) at System.Linq.Enumerable.Any[TSource](IEnumerable
1 source, Func2 predicate)处的索引>
【问题讨论】:
-
什么不起作用?你有任何错误吗?