惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Hacker News: Ask HN
Hacker News: Ask HN
H
Heimdal Security Blog
S
Secure Thoughts
Help Net Security
Help Net Security
The Hacker News
The Hacker News
T
Threatpost
T
Troy Hunt's Blog
T
Threat Research - Cisco Blogs
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Simon Willison's Weblog
Simon Willison's Weblog
WordPress大学
WordPress大学
TaoSecurity Blog
TaoSecurity Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
Cisco Talos Blog
Cisco Talos Blog
Microsoft Security Blog
Microsoft Security Blog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
阮一峰的网络日志
阮一峰的网络日志
Security Latest
Security Latest
Forbes - Security
Forbes - Security
The Last Watchdog
The Last Watchdog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
月光博客
月光博客
博客园 - 三生石上(FineUI控件)
A
About on SuperTechFans
C
Cybersecurity and Infrastructure Security Agency CISA
小众软件
小众软件
Microsoft Azure Blog
Microsoft Azure Blog
Google Online Security Blog
Google Online Security Blog
N
Netflix TechBlog - Medium
W
WeLiveSecurity
Google DeepMind News
Google DeepMind News
S
Securelist
Jina AI
Jina AI
酷 壳 – CoolShell
酷 壳 – CoolShell
G
GRAHAM CLULEY
G
Google Developers Blog
aimingoo的专栏
aimingoo的专栏
C
Cisco Blogs
量子位
有赞技术团队
有赞技术团队
雷峰网
雷峰网
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
S
SegmentFault 最新的问题
T
The Exploit Database - CXSecurity.com
MyScale Blog
MyScale Blog
A
Arctic Wolf
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog

博客园 - 星空竹月

Div中文字竖直居中的问题 ASP入门基础教程-VBScript概述及基本元素 第一次安装sql2000挂起无法安装的问题 asp.net(c#)成条形码[转] 关于文章列表如何直接显示文章类别名的问题 Page_PreInit在网页传值的应用 利用.net的强大功能发送email - 星空竹月 - 博客园 如何在asp.net中关闭B页面时,自动刷新A页面? - 星空竹月 - 博客园 ASP.net(c#)做返回上一页效果(后退)--代码 前进和后退按钮特效代码 - 星空竹月 - 博客园 文件上传实例(文件上传,自动重命名,自动添加文件夹) ASP.NET中文显示乱码之解决方法 限制显示字数 asp.net中,限制显示字数的问题? 将截断字符串或二进制数据。 IE6下透明PNG图片的显示 IE不支持PNG图片透明效果,怎么办 配置AjaxControlToolkit 怎样换网页中的鼠标图案??换成其他图片
在页面和Datalist控件中判断是否为今天 - 星空竹月 - 博客园
星空竹月 · 2007-09-13 · via 博客园 - 星空竹月

研究了一天,查了很多资料,终于搞明白了,呵呵
前台代码:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ifnow.aspx.cs" Inherits="TEST_ifnow" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
    
<title>在页面和Datalist控件中判断是否为今天</title>
</head>
<body>
    
<form id="form1" runat="server">
    
<div>
        
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
        
<br />
        
<asp:DataList ID="DataList1" runat="server" DataSourceID="SqlDataSource1" OnItemDataBound="DataList1_ItemDataBound">
            
<ItemTemplate>
                ID:
                
<asp:Label ID="ArticlsIDLabel" runat="server" Text='<%# Eval("ID") %>'></asp:Label><br />
                Title:
                
<asp:Label ID="TitleLabel" runat="server" Text='<%# Eval("Title") %>'></asp:Label><br />
                Content:
                
<asp:Label ID="ContentLabel" runat="server" Text='<%# Eval("Content") %>'></asp:Label><br />
                AddTime:
                
<asp:Label ID="AddTimeLabel" runat="server" Text='<%# Eval("AddTime") %>'></asp:Label><br />
                
<br />
            
</ItemTemplate>
        
</asp:DataList><asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:NewWebSiteConnectionString %>"
            SelectCommand
="SELECT * FROM [Articl]"></asp:SqlDataSource>
    
</div>
    
</form>
</body>
</html>

后台CS代码:

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class TEST_ifnow : System.Web.UI.Page
{
    
protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Text 
= DateTime.Now.ToLongDateString();
        
string dt = Label1.Text;
        
string mydt1 = "2007-9-13 15:35:13";
        DateTime mydt 
= Convert.ToDateTime(mydt1);
        
//DateTime dt=(DateTime)Label1.Text;
        if (mydt.ToLongDateString()== DateTime.Now.Date.ToLongDateString())
        {
            Response.Write(
"今天");
        }
        
else
        {
        Response.Write(
"不是今天");
        }
    }
    
protected void DataList1_ItemDataBound(object sender, DataListItemEventArgs e)
    {
        
if (e.Item.ItemIndex > -1)
        {
            
string time = ((Label)e.Item.FindControl("AddTimeLabel")).Text;
            DateTime dt 
= Convert.ToDateTime(time);
            
if (dt.ToShortDateString() == DateTime.Now.Date.ToShortDateString())
            {
                ((Label)e.Item.FindControl(
"AddTimeLabel")).Text = "今天";
            }
            
else
            {
                ((Label)e.Item.FindControl(
"AddTimeLabel")).Text = "以前";
            }
            
//((Label)e.Item.FindControl("Label3")).Text = aaa;
            
//Label2.Text = ((Label)e.Item.FindControl("Label3")).Text;
        }

    }
}

欢迎各位支出不足之处或更好的处理方法,谢谢