【发布时间】:2014-08-29 11:14:40
【问题描述】:
我在 Default.aspx.cs 类中,我想将列表框中的项目传递给文本框。列表框中的项目未被选中。所以我会有一个按钮,当我点击它时,我希望列表框中的项目也显示在文本框中。请帮帮我。
【问题讨论】:
标签: asp.net
我在 Default.aspx.cs 类中,我想将列表框中的项目传递给文本框。列表框中的项目未被选中。所以我会有一个按钮,当我点击它时,我希望列表框中的项目也显示在文本框中。请帮帮我。
【问题讨论】:
标签: asp.net
使用 foreach 循环并遍历您的列表框,获取每个项目的文本/值并将其附加到您的文本框。在您的按钮单击事件中,
protected void Button1_Click(object sender, EventArgs e)
{
txtItems.Text = "";
string result ="";
foreach (ListItem li in lbItems.Items)
{
result += li.Value + ",";
}
// Remove the trailing comma in the end
txtItems.Text = result.Remove(result.LastIndexOf(","),1);
}
【讨论】: