By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,357 Members | 1,021 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,357 IT Pros & Developers. It's quick & easy.

How to display multiple spaces in a dropdownlist?

P: n/a
>

How to display multiple spaces in a dropdownlist

webform1.aspx

<asp:DropDownList id="DropDownList1"
runat="server"></asp:DropDownList>

VB.NET Code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim i As Integer
For i = 0 To 10
DropDownList1.Items.Add("Item Number" + SpaceDDL(10) + i.ToString)
Next
End Sub

Private Function SpaceDDL(ByVal numberOfSpaces As Integer) As String
Dim Spaces As String
Dim i As Integer
For i = 0 To numberOfSpaces
Spaces &= "&nbsp;"
Next
Return Server.HtmlDecode(Spaces)
End Function

C# Code

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
for(int i = 0 ;i<=10;i++)
{
DropDownList1.Items.Add("Item Number" + SpaceDDL(10) +
i.ToString());
}
}

string SpaceDDL(int numberOfSpaces )
{
string Spaces="";
for(int i = 0 ;i<=numberOfSpaces;i++)
{
Spaces += "&nbsp;";
}
return Server.HtmlDecode(Spaces);
}
Nov 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Hi,

Do not apply HtmlDecode() on the '&nbsp;' sequence; use it as is (in your
SpaceDDL()).

"Anonieko Ramos" <an******@hotmail.com> wrote in message
news:56**************************@posting.google.c om...


How to display multiple spaces in a dropdownlist

webform1.aspx

<asp:DropDownList id="DropDownList1"
runat="server"></asp:DropDownList>

VB.NET Code

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'Put user code to initialize the page here
Dim i As Integer
For i = 0 To 10
DropDownList1.Items.Add("Item Number" + SpaceDDL(10) + i.ToString)
Next
End Sub

Private Function SpaceDDL(ByVal numberOfSpaces As Integer) As String
Dim Spaces As String
Dim i As Integer
For i = 0 To numberOfSpaces
Spaces &= "&nbsp;"
Next
Return Server.HtmlDecode(Spaces)
End Function

C# Code

private void Page_Load(object sender, System.EventArgs e)
{
// Put user code to initialize the page here
for(int i = 0 ;i<=10;i++)
{
DropDownList1.Items.Add("Item Number" + SpaceDDL(10) +
i.ToString());
}
}

string SpaceDDL(int numberOfSpaces )
{
string Spaces="";
for(int i = 0 ;i<=numberOfSpaces;i++)
{
Spaces += "&nbsp;";
}
return Server.HtmlDecode(Spaces);
}
Nov 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.