【发布时间】:2017-07-29 19:05:23
【问题描述】:
我的基本结构:
public partial class _Search : BasePage
{
private string[] catPath = new string[3]; //set string array
...more code...
protected void Categories_DataBound(object sender, EventArgs e)
{
for (int i = 3; i > 0; i--)
{
catPath[i] = somestring; //fills array
}
}
...more code...
protected void Cat1_Click(object sender, EventArgs e)
{
MessageBox.Show(catPath[0]); //uses array
}
}
我在Click 事件中使用我的catPath 数组时遇到问题,它是空的,好像从未在DataBound 方法中设置过一样。我知道它是在 Click 事件之前设置的,因为我在 DataBound 方法中使用了 MessageBox 来显示数组中的值,所以我做错了什么?
我尝试过使用 List 进行类似的操作,但遇到了同样的问题。不过,基本字符串等其他变量也可以正常工作。
谢谢!
【问题讨论】:
-
" 但其他变量(如基本字符串)运行良好。"那么什么类型不能正常工作呢?
-
字符串数组
标签: c# asp.net visual-studio-2015 asp.net-4.6