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.

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章