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

来源:互联网 发布:linux下载安装包命令 编辑:程序博客网 时间:2024/04/30 21:14

我们知道: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.