locked
Collapsing spaces on Datatext field RRS feed

  • Question

  • User-2110133321 posted

    Hello and have a good day!

    could someone pls help me with this:

    I append 2 fields of a List items to 1field like this with 4 spaces between 2 fields:

    lptItem[lptItem.IndexOf(i)].Tuyen = lptItem[lptItem.IndexOf(i)].Tuyen + "     " + lptItem[lptItem.IndexOf(i)].ThoiGianKhoiHanh;

    Then I bind it to a bulleted List:

    BLstDuongBo.DataTextField = "Tuyen";

    but space will collapse to " ", I cant us nbsp 'cause it's a text filed. Pls help me with this :(, I want 4 spaces :(.






    Tuesday, September 21, 2010 12:01 AM

Answers

  • User455271935 posted

    Hi ..

    Use this.

    public static string Padding(int count)
    {
      if (count == 0)
      {
        return string.Empty;
      }
      string[] s = new string[count];
      for (int i = 0; i < count; ++i)
      {
        s[i] = "&nbsp;";
      }
      return HttpUtility.HtmlDecode(string.Join("", s));
    }

     

    You can bind it to the drop down list as you like ..

    for example

    DropDownList3.Items[0].Text =

     String.Concat(DropDownList1.Items[0].Text, Padding(4), DropDownList2.Items[0].Text);

    or

    DropDownList3.Items[0].Text = DropDownList1.Items[0].Text + Padding(4) + DropDownList2.Items[0].Text;

     

     In your case you can use like this

    lptItem[lptItem.IndexOf(i)].Tuyen = lptItem[lptItem.IndexOf(i)].Tuyen + Padding(4)  + lptItem[lptItem.IndexOf(i)].ThoiGianKhoiHanh;

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, September 21, 2010 1:44 AM