我正在尝试将gridview中的值存储到会话变量中,使用Gridview中的按钮,该按钮放置在内容页面中并进一步放入手风琴中,所以首先我必须找到内容持有者,这样做得很好,我发现手风琴,然后gridview控制,也找到了正确的。但是当我想从Grid视图中找到值时抛出错误..为什么?因为我在gridview上有按钮用于选择记录,但是我使用按钮的点击事件也是..可能这是问题.. Plz帮助
ContentPlaceHolder MyContentPH = (ContentPlaceHolder)Master.FindControl("ContentPlaceHolder1");
AjaxControlToolkit.Accordion MyAccordion = (AjaxControlToolkit.Accordion)MyContentPH.FindControl("Accordion1");
if (MyAccordion != null)
{
GridView MessageGrid = (GridView)MyAccordion.FindControl("GridView1");
Session["UserMessage"] = ((Label)MessageGrid.SelectedRow.FindControl("Label8")).Text;
Session["Name"] = ((Label)MessageGrid.SelectedRow.FindControl("Label1")).Text;
Session["Email"] = ((Label)MessageGrid.SelectedRow.FindControl("Label2")).Text;
Session["MessageID"] = ((Label)MessageGrid.SelectedRow.FindControl("Label9")).Text;
}
Response.Redirect("AdminRep.aspx");
引发此错误:
Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.