ASP:Literal控件用法
刚开始学.NET的朋友可能不清楚Literal和Label到底有什么区别,其实它们也只有一个区别,就是在转换成客户端Html代码后,Label就成了,而Literal则是什么标记都不带,下面进入正题: 昨天做一个网站的视频新闻管理,首先我要在页面里添加一个播放器,如下:
1 2 3 4 5 6 7 8 9
那么如何让这个播放器能根据我们传的参数不同而播放不同的内容呢?上面一段Html代码的第5行就指明了这个播放器播放的内容来源,为了实现能根据参数不同播放不同的内容,我们将其Value值设置为一个Literal控件,然后在后置代码中动态的对Literal的Text属性赋值就OK了。代码如下:
![](/Images/OutliningIndicators/ExpandedBlockStart.gif) /**//// /// Author: SHY520 /// http://pw.cnblogs.com /// public class ShowVideoContent : System.Web.UI.UserControl![](/Images/OutliningIndicators/ExpandedBlockStart.gif) { protected System.Web.UI.WebControls.Literal lt_reader; protected System.Web.UI.WebControls.Literal lt_vdate; protected System.Web.UI.WebControls.Literal lb_author; protected System.Web.UI.WebControls.Literal lt_resource; protected System.Web.UI.WebControls.Label lb_title;![](/Images/OutliningIndicators/InBlock.gif) //注意:写在Object中的Literal需要我们手工定义 Literal lt_src;![](/Images/OutliningIndicators/InBlock.gif) private void Page_Load(object sender, System.EventArgs e)![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { if(Request.QueryString["id"] != null)![](/Images/OutliningIndicators/ExpandedSubBlockStart.gif) { int id = int.Parse(Request.QueryString["id"].ToString()); //得到视频新闻内容 VideoContent vc = VideoContent.Find(id);![](/Images/OutliningIndicators/InBlock.gif) lt_reader.Text = vc.Announcer; lt_vdate.Text = vc.Vdate.ToShortDateString(); lb_author.Text = vc.Author; lt_resource.Text = vc.Resource; lb_title.Text = vc.Videotitle; //对播放内容赋值 lt_src.Text = vc.Linkurl; } } }
Literal的用法非常灵活,希望上面的说的能对您有所帮助!
posted on
2006-06-05 20:37
Daniel Pang
阅读(26423)
评论(9)
编辑
收藏
举报
|