首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

有关问题请问.请指点

2012-01-05 
问题请教.请指点[NullReferenceException:未将对象引用设置到对象的实例。]Manage_AddProduct_Question.Bin

问题请教.请指点
[NullReferenceException:   未将对象引用设置到对象的实例。]
      Manage_AddProduct_Question.BindddlProduct()   in   e:\vss\AocLife\Source\prototype\AocLife\AocLife\Manage\AddProduct_Question.aspx.cs:36
      Manage_AddProduct_Question.Page_Load(Object   sender,   EventArgs   e)   in   e:\vss\AocLife\Source\prototype\AocLife\AocLife\Manage\AddProduct_Question.aspx.cs:22
      System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr   fp,   Object   o,   Object   t,   EventArgs   e)   +15
      System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object   sender,   EventArgs   e)   +34
      System.Web.UI.Control.OnLoad(EventArgs   e)   +99
      System.Web.UI.Control.LoadRecursive()   +47
      System.Web.UI.Page.ProcessRequestMain(Boolean   includeStagesBeforeAsyncPoint,   Boolean   includeStagesAfterAsyncPoint)   +106


  protected   void   Page_Load(object   sender,   EventArgs   e)
        {
                Power.Judge(this);
                if   (!IsPostBack)
                {
                        BindddlProduct();
                        bindQuestion(Convert.ToInt32(ddlProduct.SelectedValue));
                }
        }
        private   void   BindddlProduct()
        {
                ProductBL   ProductBL   =   new   ProductBL();
                SqlDataReader   dr   =   ProductBL.SelectProduct();
                ddlProduct.DataSource   =   dr;
                ddlProduct.DataTextField   =   "ProductName ";
                ddlProduct.DataValueField   =   "ProductKey ";
                ddlProduct.DataBind();
                dr.Close();

                ddlProduct.Items.FindByValue(GetProductKey().ToString()).Selected=true;   这句话报错
        }

        private   void   bindQuestion(int   ProductKey)
        {
                QuestionBL   questionBL   =   new   QuestionBL();
                SqlDataReader   sdr   =   questionBL.NotinProductQuestion(ProductKey);
                ddlQuestion.DataSource   =   sdr;
                ddlQuestion.DataTextField   =   "Title ";
                ddlQuestion.DataValueField   =   "QuestionKey ";
                ddlQuestion.DataBind();
                sdr.Close();


          }

        private   int   GetProductKey()
        {
                int   ProductKey   =   0;
                try
                {
                        ProductKey   =   Convert.ToInt32(Request.QueryString[ "ProductKey "]);
                }
                catch
                {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(),   " ",   " <script> alert( '非法操作! ');window.location= 'EditProduct.aspx ' </script> ");

                }
                finally
                {
                        if   (ProductKey   ==   0)
                        {
                                ClientScript.RegisterStartupScript(ClientScript.GetType(),   " ",   " <script> alert( '没有数据! ');window.location= 'EditProduct.aspx ' </script> ");
                        }
                }
                return   ProductKey;
        }

        protected   void   btnSubmit_Click(object   sender,   EventArgs   e)
        {
                Product_QuestionBL   productQuestionBL   =   new   Product_QuestionBL();

                TR_P_Product_Question   productQuestion   =   new   TR_P_Product_Question();
                productQuestion.QuestionKey   =   Convert.ToInt32(ddlQuestion.SelectedValue);
                productQuestion.ProductKey   =   Convert.ToInt32(ddlProduct.SelectedValue);
                productQuestion.Sort   =   Convert.ToInt32(txtSort.Text);

                bool   result   =   productQuestionBL.InsertProductQusestion(productQuestion);
                if   (result)
                {
                        ClientScript.RegisterStartupScript(ClientScript.GetType(),   " ",   " <script> alert( '添加成功! ') </script> ");
                }
                else
                {


                        ClientScript.RegisterStartupScript(ClientScript.GetType(),   " ",   " <script> alert( '添加失败! ') </script> ");
                }

                txtSort.Text   =   "0 ";
                BindddlProduct();
                bindQuestion(Convert.ToInt32(ddlProduct.SelectedValue));
        }




[解决办法]
what r u doing?
[解决办法]
查看源文件,看一下你的ddlProduct里是否包含FindByValue的值,估计是没有此值报的错

热点排行