日期:2014-05-19  浏览次数:20517 次

如何根据传来的值显示内容?
有个新闻发布,左侧是导航,动态显示的新闻类型,比如有“新闻1”,“新闻2”,右边根据左边传来的新闻类型显示新闻的文章的标题,现在有个小问题,就是在第一次加载的时候想显示所有新闻,就是说没有传来的值,请问该怎么办呢?

------解决方案--------------------
if(!Page.IsPostBack)
{
if(string.IsNullOrEmpty(Request.QueryString[ "NewsId "])
{
this.repeater.DataSource=显示所有的新闻
}
else
{
int newsId=Convert.ToInt32(Request.QueryString[ "NewsId "]);
this.repeater1.datasource= 根据newsId绑定数据
}

}
------解决方案--------------------
Request.QueryString[ "NewsId "] 直接判断是不是Null 或者为空就可以了

其他的没啥
------解决方案--------------------
if(!Page.IsPostBack)
{
if(Request.QueryString[ "NewsId "]!=null)
{
if(Request.QueryString[ "NewsId "].ToString()==string.empty())
{
this.repeater.DataSource=显示所有的新闻
}
else
{
int newsId=Convert.ToInt32(Request.QueryString[ "NewsId "]);
this.repeater1.datasource= 根据newsId绑定数据
}
}
else
{
int newsId=Convert.ToInt32(Request.QueryString[ "NewsId "]);
this.repeater1.datasource= 根据newsId绑定数据

}
}