Click here to Skip to main content
15,915,509 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
I have listbox in run mode as follows

Ramesh
Suresh
Rakesh

I want New line in listbox in run mode i want output as folows

Ramesh

Suresh

Rakesh

for that how can i do in asp.net using csharp.
Posted

after each entry, you can add the following:

myListBox.Items.Insert(0, "");

you can also considering itemheight instead of adding blank line
 
Share this answer
 
v2
without adding any empty items you can try applying css padding[^] for listbox items. check below answers for how you can do it in asp.net c#
http://forums.asp.net/t/1523278.aspx?Spacing+between+items+in+Listbox[^]
 
Share this answer
 
The listbox is being rendered as select tag in html, so set height property of the option tags using css and javascript, e.g.:
XML
<form id="form1" runat="server">
    <asp:ListBox id="listbox1" rows="3" runat="server">
        <asp:ListItem selected="true">Item 1</asp:ListItem>
        <asp:ListItem>Item 2</asp:ListItem>
        <asp:ListItem>Item 3</asp:ListItem>
        <asp:ListItem>Item 4</asp:ListItem>
        <asp:ListItem>Item 5</asp:ListItem>
        <asp:ListItem>Item 6</asp:ListItem>
    </asp:ListBox>
</form>
<script>
    var options = document.getElementById("<%= listbox1.ClientID %>").options;
    for (i = 0; i < options.length; i++)
    {
        document.getElementById("listbox1").options[i].style.height = "25px";
    }
</script>

You may want to experiment with different css properties like padding, margin etc.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900