前台代码:通过Repeater列表记录行(多行),每一行前页有一个供选择的:<input name="check" ID="LID" type="checkbox" value="<%# Eval("ID") %>" />有个按钮:执行操作
执行操作事件中:
string IDstr = Request.Form["check"].ToString();当check有选择的时候,代码正常;但是当check无任何选择时提示出错:未将对象引用设置到对象的实例。行 91:     protected void Button1_Click(object sender, EventArgs e)
行 92:     {
行 93:         string IDstr = Request.Form["check"].ToString();
行 94:         //string IDstr2 = Request.Form["LID"].ToString();
行 95:         Response.Write("<scripr>alert('删除失败!"+IDstr+"');</script>");
 请各位指点,谢谢

解决方案 »

  1.   

    先判断一下有没有选择if(Request.Form["check"]!==null)
    {
    //////
    }或者在前台直接用非空验证控件。
      

  2.   

    Request.Form["check"]返回的可能为null,
    改下。Request.Form["check"]==null?"":Request.Form["check"].ToString();
      

  3.   

        protected void Button1_Click(object sender, EventArgs e)
        {
            string IDstr = Request.Form["check"];
            if (Request.Form["check"]!="" && Request.Form["check"]!=null)
            {
              string IDstr2 = Request.Form["check"].ToString();
              Response.Write("<scripr>alert('有选择!');</script>");        }else
            {
                Response.Write("<scripr>alert('请选择再进行操作!');</script>");
            }
        }
      

  4.   

    额,不好意思 当是RadioButtonList或textbox的时候才能用非空验证控件