我无法弄清楚为什么这行代码
Image1.ImageUrl = displayPath + photoFileList[index].ToString();
适用于Button1点击事件,但不适用于btnNext点击事件(点击button1加载数据后)。
如果我在button1中注释掉这一行,那么在点击button1之后它将无法在btnNext中工作
public List<string> photoFileList = new List<string>();
public int index = 0;
public string loadPath = "\\\\intranet.org\\Photo Album\\Employees\\";
public string displayPath = "////intranet.org//Photo Album//Employees//";
protected void Button1_Click(object sender, EventArgs e)
{
DirectoryInfo di = new DirectoryInfo(loadPath);
FileInfo[] rgFiles = di.GetFiles("*.JPG");
foreach (FileInfo fi in rgFiles)
{
photoFileList.Add(fi.Name);
}
// this next line works here if i uncomment it but it won't work in btnNext click
//Image1.ImageUrl = displayPath + photoFileList[index].ToString();
}
protected void btnNext_Click(object sender, EventArgs e)
{
Image1.ImageUrl = displayPath + photoFileList[index].ToString();
}
答案 0 :(得分:0)
您正在按钮1中获取目录信息,但由于您没有将其存储在说明会话信息中,它会在客户端的下一个请求中丢失,下一个按钮单击。尝试将字符串列表存储到会话变量中,并在下一个单击事件中检索它。