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又不能了
控件名称也没有错
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;
}
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;
}
}
编译主要检查语法,比如int NewsId = Convert.ToInt32(Request.QueryString["id"]);右侧在运行时才取到值,编译时为空。把一个空值赋给int要出错。其他问题也一样
我是猎头公司的helen
现在有上海的。net开发的职位
4,5年的c#开发经验
英文可以沟通
项目很不错
难得的机会
有感兴趣的朋友联系我
msn:[email protected]
邮箱:[email protected]
if(int.TryParsr(Request.QueryString["id"].toString(),out NewsId))
{
News SingleNews = new News();
SingleNews = News.GetNewsByNewsId(NewsId);
}
看看GetNewsByNewsId方法里值是否有。是否能查询出数据。