c# - Trying to get my head wrapped around Conditional NULL syntax -


i've got asp.net search page displays sql bound listview after search button clicked. in emptydatatemplate, i've got asp label based on id searched in message. "no results found " kinda thing.

here's original codebehind button click:

protected void btnsearch_command(object sender, commandeventargs e) {      label lbl = (label)lvmatorders.controls[0].controls[0].findcontrol("lblprojectid");     if (lbl != null)  // means emptydatatemplate used, else itemtemplate     {          if (string.isnullorempty(txtprojectid.text))         {             lbl.text = "#####";         }         else         {             lbl.text = txtprojectid.text;         }      } } 

am correct in understanding can reduce down following?

label lbl = (label)lvmatorders.controls[0].controls[0].findcontrol("lblprojectid"); lbl?.text = (string.isnullorempty(txtprojectid.text)) ? "#####" : txtprojectid.text; 

the main goal here make sure code attempts assign either "#####" or txtprojectid.text lbl.text doesn't executed if page has results previous search displayed page isn't showing emptydatatemplate , no lblprojectid assign text to.

will lbl?.text line attempted if page in itemtemplate mode?

no, code not compile, error "the left-hand side of assignment must variable, property or indexer"

you can not use .? operator on left hand side of equals sign, right hand side.


Comments

Popular posts from this blog

c# - Update a combobox from a presenter (MVP) -

How to understand 2 main() functions after using uftrace to profile the C++ program? -

How to put a lock and transaction on table using spring 4 or above using jdbcTemplate and annotations like @Transactional? -