How to display multiple spaces in a dropdownlist?

A

Anonieko Ramos

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);
}
 
S

Shiva

Hi,

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

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);
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,810
Latest member
Kassie0918

Latest Threads

Top