如何在asp.net [服务器端]的文本文件中保存列表框项?

时间:2015-11-23 06:32:08

标签: c# asp.net

我使用了2个列表框控件
例如:

list box 1   list box 2
hi
bye
how

然后传递第二个列表框中的值
例如:

 list box 1   list box 2
  how          hi
               bye

我有用于保存第二个列表框项目的文本文件(记事本)的代码。

1 个答案:

答案 0 :(得分:1)

循环通过ListBox,然后将其写入您的txt文件。

 string sListBoxItems = "";
  for(int i = 0; i < listBox1.Items.Count; i++) {
     sListBoxItems += listBox1.Items[i].ToString();
  }

File.WriteAllText("yourfile.txt", sListBoxItems );