c# - How to check in all visible rows CELLs for string.IsNullOrEmpty and IsDateEmpty -


i have table rows show/hide button click event. want check visible rows cell index string.isnullorempty , isdateempty. how this?

enter image description here

the following code(for check visible cell[0] textbox) not working:

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 text"; } 

the following code(for check second cell 1 datetimecontrol) not working:

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 date!"; } 

this following error

system.argumentoutofrangeexception: specified argument out of range of valid values. parameter name: index @ system.web.ui.controlcollection.get_item(int32 index) @ lirex.waybillmodule.b__2f(tablerow row) @ system.linq.enumerable.any[tsource](ienumerable1 source, func2 predicate)

you can try below if work, check empty text box on visible row, modify check other control type.

        var tablerows = table1.rows.cast<tablerow>().where(row => row.visible);          bool hasemptyfield = false;         foreach (var row in tablerows.where(row => row.cells.cast<tablecell>()             .selectmany(                 item => item.controls.cast<control>()                     .where(cntrl => cntrl.gettype() == typeof (textbox)))             .any(cntrl => string.isnullorempty(((textbox) cntrl).text))))         {             hasemptyfield = true;             break;         }          if (hasemptyfield)         {             //do want...         } 

edited answer. last query checking last visible row. made changes , using clause instead of last in getting visible rows.. changes include loop each row.

below original code posted checking last visible row only.

        var tablerow = table1.rows.cast<tablerow>().last(row => row.visible);         var hasemptytextbox =             tablerow.cells.cast<tablecell>()                 .selectmany(                     item => item.controls.cast<control>()                         .where(cntrl => cntrl.gettype() == typeof(textbox)))                 .any(cntrl => string.isnullorempty(((textbox)cntrl).text)); 

Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -