如何使用c#为列表框添加新行 [英] how to give new line to listbox using c#

查看:130
本文介绍了如何使用c#为列表框添加新行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在运行模式下的列表框如下



Ramesh

Suresh

Rakesh



我想要在运行模式下列表框中的新行我希望输出为folows



Ramesh



Suresh



Rakesh



我怎么办asp.net使用csharp。

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.

推荐答案

每次输入后,你可以添加以下内容:



myListBox .Items.Insert(0,);



您还可以考虑itemheight而不是添加空行
after each entry, you can add the following:

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

you can also considering itemheight instead of adding blank line


而不添加您可以尝试应用css填充的任何空白项目[ ^ ]。检查以下答案,了解如何在asp.net中完成它#

http://forums.asp.net/t/1523278.aspx?Spacing+between+items+in+Listbox [ ^ ]
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[^]


列表框呈现为在html中选择标签,所以使用css和javascript设置选项标签的高度属性,例如:

The listbox is being rendered as select tag in html, so set height property of the option tags using css and javascript, e.g.:
<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>



你可能想尝试不同的填充,边距等css属性


You may want to experiment with different css properties like padding, margin etc.


这篇关于如何使用c#为列表框添加新行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆