ASP.NET DropDownList列表项添加前导空格(Leading Space)的两种方法

我们知道:RFC 1866中定义了一个named entity,即 ASCII是160;
方法一:
     char nbsp = (char)0xA0;
     dropDownList.Items.Add( new ListItem( "test3".PadLeft(10,nbsp) , "4" ) );
     注释:
     String.PadLeft( int totalWidth , char paddingChar )
 
      Parameters:
           totalWidth:
              The number of characters in the resulting string, equal to the number of
              original characters plus any additional padding characters.
                   
           paddingChar:
              A Unicode padding character.
     Returns:
             A new string that is equivalent to this instance, but right-aligned and padded
             on the left with as many paddingChar characters as needed to create a length
             of totalWidth. Or, if totalWidth is less than the length of this instance,
             a new string that is identical to this instance.

方法二:
     dropDownList.Items.Add( new ListItem( Server.HtmlDecode( "   ") + "test3", "4" ) );
     注释:
      Server.HtmlDecode( string s )
      Parameters:
          s:
            The HTML string to decode.
      Returns:
            The decoded text.
      Summary:
            Decodes an HTML-encoded string and returns the decoded string.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值