Initialize listitem with blanks?

Posted by VBartilucci on Stack Overflow See other posts from Stack Overflow or by VBartilucci
Published on 2011-06-29T14:31:53Z Indexed on 2011/06/29 16:22 UTC
Read the original article Hit count: 219

Filed under:
|
|
|
|

Say I have a list made up of a listitem which contains three strings. I add a new listitem, and try to assign the values of said strings from an outside source.

If one of those items is unassigned, the value in the listitem remains as null (unassigned). As a result I get an error if I try to assign that value to a field on my page.

I can do a check on isNullOrEmpty for each field on the page, but that seems inefficient. I'd rather initialize the values to "" (Empty string) in the codebehind and send valid data.

I can do it manually:

            ClaimPwk emptyNode = new ClaimPwk();
            emptyNode.cdeAttachmentControl = "";
            emptyNode.cdeRptTransmission = "";
            emptyNode.cdeRptType = "";
            headerKeys.Add(emptyNode);

But I have some BIG list items, and writing that for those will get tedious.

So is there a command, or just plain an easier way to initialize a listitem to empty string as opposed to null?

Or has anyone got a better idea?

© Stack Overflow or respective owner

Related posts about c#

Related posts about list