public string sxh;
    public string cpmc;
    public string wtdw;
    public string rq;
    public string ph;
    public string cpgg;
    public string gx;
    public string pz;
    public string sh;
    public string[] hf;
    public string[] zmd;
    public string[] tjmd;
    public string[] qkl;
    public string[] kyqd;
    public string[] dzl;
    public string[] bz;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Request.QueryString["sxh"] != null)
            {
                Bind();
            }
            if (SessionBox.GetUserSession().Group == "报告审核")
            {
                auditdiv.Visible = true;
            }
        }
    }
protected void Bind()
{
...
int i = ds.Tables[0].Rows.Count;
        if (i > 8)
        {
            hf = new string[i];
            zmd = new string[i];
            tjmd = new string[i];
            qkl = new string[i];
            kyqd = new string[i];
            dzl = new string[i];
            bz = new string[i];
            pagediv.Visible = true;
        }
        else
        {
            hf = new string[8];
            zmd = new string[8];
            tjmd = new string[8];
            qkl = new string[8];
            kyqd = new string[8];
            dzl = new string[8];
            bz = new string[8];
            pagediv.Visible = false;
        }
}protected void LinkButton5_Click(object sender, EventArgs e)
    {
        if (BLL.ReportsBll.ShimohuaHasPassed(SessionBox.GetUserSession().Rank, SessionBox.GetUserSession().UserNumber, Request.QueryString["sxh"].ToString()) > 0)
        {
            JScript.Alert("审核通过。");
            Response.Redirect("~/main/smhreport.aspx?sxh=" + Request.QueryString["sxh"].ToString());
        }
    }红色这行,如果不加,就会提示错误。System.NullReferenceException: 未将对象引用设置到对象的实例
<tr>
                <td valign="middle">
                    1</td>
                <td valign="middle"><%=hf[0] %>
                </td>

                <td valign="middle"><%=zmd[0] %>
                </td>
                <td valign="middle"><%=tjmd[0] %>
                </td>
                <td valign="middle"><%=qkl[0] %>
                </td>
                <td valign="middle"><%=kyqd[0] %>
                </td>
                <td valign="middle"><%=dzl[0] %>
                </td>
                <td valign="middle"><%=bz[0] %>
                    </td>
            </tr>
应该就是hf没有实例化吧?请问如何解决啊?重定向页面那行的话,弹出对话框就失效了。

解决方案 »

  1.   

     public static void AlertAndRedirect(System.Web.UI.Page page, string strUrl,string Msg)
        {
            page.ClientScript.RegisterStartupScript(page.GetType(), "M" + DateTime.Now.Ticks.ToString(), "<script>alert('" + Msg + "');location.href='" + strUrl + "'</script>");
        }
      

  2.   

    引用楼主 sgpxd 的帖子:
      
    重定向页面那行的话,弹出对话框就失效了。 
    試試這樣的: Response.Write(" <SCRIPT>alert('审核通过。') <SCRIPT/>;location.href='~/main/smhreport.aspx?sxh=" + Request.QueryString["sxh"].ToString()'"); 
    红色这行,如果不加,就会提示错误。System.NullReferenceException: 未将对象引用设置到对象的实例 
    因爲: Request.QueryString["sxh"]沒有獲取值
      

  3.   

    这个还是用控件吧.label就行
    <td valign="middle"> <%=hf[0] %> 
    这种都换成label,在后台赋值.
      

  4.   


    多谢,但是不用redirect ,地址栏的地址也是有sxh=0的?
      

  5.   


    可以用js 实现跳转
            ClientScript.RegisterStartupScript(GetType(), "jsGo", " <script>alert('" + Msg + "');location.href='/main/smhreport.aspx?sxh=" + Request.QueryString["sxh"].ToString()+ "'; </script>"); 
    是因为
     if (!IsPostBack) 
            { 
                if (Request.QueryString["sxh"] != null) 
                { 
                    Bind(); 
                } 
                if (SessionBox.GetUserSession().Group == "报告审核") 
                { 
                    auditdiv.Visible = true; 
                } 
            } 
    你在第一次加载的时候进行了判断,如果get方式 没有sxh 这个参数,就不运行Bind 这个方法了,所以
    protected void Bind() 

    ... 
    int i = ds.Tables[0].Rows.Count; 
            if (i > 8) 
            { 
                hf = new string[i]; 
                zmd = new string[i]; 
                tjmd = new string[i]; 
                qkl = new string[i]; 
                kyqd = new string[i]; 
                dzl = new string[i]; 
                bz = new string[i]; 
                pagediv.Visible = true; 
            } 
            else 
            { 
                hf = new string[8]; 
                zmd = new string[8]; 
                tjmd = new string[8]; 
                qkl = new string[8]; 
                kyqd = new string[8]; 
                dzl = new string[8]; 
                bz = new string[8]; 
                pagediv.Visible = false; 
            } 

    hf 这个数组就没有进行初始化
      

  6.   

    js的跳转还是提示System.NullReferenceException: 未将对象引用设置到对象的实例 
      

  7.   

    这个方法本身就是不对的.你页面刷新之后"<%%>"里的内容就已经过了生命周期了.如果你非要这么做就在bind一次吧.
    这样:
    JScript.Alert("审核通过。"); 
    Bind();这个思路本身就错的.这么写和ASP就没区别了.
      

  8.   

    说的不准确,是" <%%>"里的的变量的值过了生命周期.你刷新一次就重新赋了一次值给hf[0],这个时候如果没有重新Bind()则hf[0]是没有值的.
      

  9.   


    那请问下,应该怎么做呢?这里我需要把数据放在一个table 中显示,
      

  10.   

    用label.在后台赋值.这个是最常用的做法.