- C# code
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e) { ListViewDataItem dataItem = (ListViewDataItem)e.Item; int index = dataItem.DisplayIndex; DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("msg.xml"));//未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll rowdata = ds.Tables[0].Rows[index]["staff"].ToString(); if (rowdata.Length > 0) { int length = rowdata.Length - 1; rowdata = rowdata.Substring(0, length); //HyperLink hyperlink1 = (HyperLink)e.Item.FindControl("HyperLink1"); //HyperLink hyperlink1 = new HyperLink(); Panel panel = (Panel)dataItem.FindControl("panel1"); string[] files = rowdata.Split('#'); int L = files.Length; for (int i = 0; i < L; i++) { string[] filename = files[i].Split('@'); //Response.Write(filename[0]); HyperLink hyperlink1 = new HyperLink(); hyperlink1.NavigateUrl = "usersUpload/" + filename[0]; //Response.Write(filename[0]); hyperlink1.Text = "<img alt='附件:'src='image/zip.jpg' style='border:0px;' /> " + filename[0] + "<br/>"; hyperlink1.ID = "file"; panel.Controls.Add(hyperlink1); //hyperlink1.Text = hyperlink1.Text+ filename[0] ; } //Response.Write(files[3]); //hyperlink1.Text = test; } bindGrid(); }public void bindGrid() { DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath("msg.xml")); if (ds.Tables.Count != 0) { ListView1.DataSource = ds.Tables[0]; ListView1.DataBind(); ds.Dispose(); Label1.Visible = false; } else { Label1.Visible = true; } }
这段代码在vs2010里运行没问题,在vs2008里会出现“未处理的“System.StackOverflowException”类型的异常出现在 mscorlib.dll”的异常,求师傅们看看这段代码哪里有问题
------解决方案--------------------------------------------------------
bindGrid中对listview进行了绑定,而你在 ListView1_ItemDataBound又调用bindGrid,继而又会触发 ListView1_ItemDataBound,造成死循环