public void BindData()
    {
        if (Request.QueryString["id"] != null)
        {
            BindNewsKind();
            int NewsId = Convert.ToInt32(Request.QueryString["id"]);
            News SingleNews = new News();
            SingleNews = News.GetNewsByNewsId(NewsId);
            this.TxtNewsTitle1.Text = SingleNews.NewsTitle;
            this.DropNewsKinds1.SelectedIndex = SingleNews.NewsKindId;
            this.WebNewsBody1.Text = SingleNews.NewsBody;
        }
        
    }
分布调试,Convert.ToInt32(Request.QueryString["id"]),取值没问题,但是就是无法赋值给NewsId,NewsId为空。很奇怪的是this.TxtNewsTitle1.Text = SingleNews.NewsTitle;竟然能赋值
换了种写法:public void BindData()
    {
        if (Request.QueryString["id"] != null)
        {
            BindNewsKind();
            //int NewsId = Convert.ToInt32(Request.QueryString["id"]);
            News SingleNews = new News();
            SingleNews = News.GetNewsByNewsId(Convert.ToInt32(Request.QueryString["id"]));
            this.TxtNewsTitle1.Text = SingleNews.NewsTitle;
            this.DropNewsKinds1.SelectedIndex = SingleNews.NewsKindId;
            this.WebNewsBody1.Text = SingleNews.NewsBody;
        }
        
    }
this.TxtNewsTitle1.Text = SingleNews.NewsTitle;可以赋值了,但是this.WebNewsBody1.Text = SingleNews.NewsBody又不能了
控件名称也没有错

解决方案 »

  1.   


        public void BindData()
        {
            int NewsId = 0;
            int.TryParse(Request.QueryString["id"], out NewsId);
                
            BindNewsKind();
                        
            News SingleNews = new News();
            SingleNews = News.GetNewsByNewsId(NewsId);
            this.TxtNewsTitle1.Text = SingleNews.NewsTitle;
            this.DropNewsKinds1.SelectedIndex = SingleNews.NewsKindId;
            this.WebNewsBody1.Text = SingleNews.NewsBody;
            
            
        }
      

  2.   

    不知道你程序具体是怎么写的,你还是改成这样吧
        public void BindData()
        {
            int NewsId = 0;
            if(int.TryParse(Request.QueryString["id"], out NewsId))
            {    
               BindNewsKind();
                        
               News SingleNews = new News();
               SingleNews = News.GetNewsByNewsId(NewsId);
               this.TxtNewsTitle1.Text = SingleNews.NewsTitle;
               this.DropNewsKinds1.SelectedIndex = SingleNews.NewsKindId;
               this.WebNewsBody1.Text = SingleNews.NewsBody;
            }
            
        }
      

  3.   

    阿非的使用OUT关键字的方法不错,这样既避免了类型转换失败带来的异常,又将转换成功后的值赋给了新的变量~
      

  4.   

    NewsId 必须先赋值,如2楼;否则编译通不过。
    编译主要检查语法,比如int NewsId = Convert.ToInt32(Request.QueryString["id"]);右侧在运行时才取到值,编译时为空。把一个空值赋给int要出错。其他问题也一样
      

  5.   

    大家好
    我是猎头公司的helen
    现在有上海的。net开发的职位
    4,5年的c#开发经验
    英文可以沟通
    项目很不错
    难得的机会
    有感兴趣的朋友联系我
    msn:[email protected]
    邮箱:[email protected]
      

  6.   

    int NewsId =0;
     if(int.TryParsr(Request.QueryString["id"].toString(),out NewsId))
    {
                News SingleNews = new News();
                SingleNews = News.GetNewsByNewsId(NewsId);
    }
               看看GetNewsByNewsId方法里值是否有。是否能查询出数据。