ASP.Net网格帮助....日期比较问题。 [英] ASP.Net Grid Help....Date Comparison Issues.

查看:102
本文介绍了ASP.Net网格帮助....日期比较问题。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨朋友们,



如果先前的2列(日期列)不同,我试图根据列值添加显示是或否文本的列超过1个月到开始日期。



前2列是开始日期和结束日期,这2列的值来自数据库。如果您需要更多信息,请告诉我



这是我要添加的代码..



Hi Friends,

I am trying to add a column which displays Yes Or No Text based on column values if the previous 2 columns(Date Columns) difference is more than 1 month to Starting Date.

The Previous 2 columns are Start Date and End Date and the values of these 2 columns are coming from database. Please let me know if you need more information

Here is the code I am adding..

Protected Sub GridView1_OnRowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim dtDOJ As DateTime = Convert.ToDateTime(e.Row.Cells(4).Text)
        Dim dtDOJ1 As DateTime = Convert.ToDateTime(e.Row.Cells(5).Text)
        
        If dtDOJ1 >= dtDOJ.AddMonths(1) Then
            e.Row.Cells(6).Text = "Yes";
        Else
            e.Row.Cells(6).Text = "No";
        End If
    End If


End Sub

推荐答案

看看下面的代码(虽然它在C#中,使用转换器用于VB):



Have a look at below code(Though its in C#,use converter for VB):

<asp:gridview id="GridView1" runat="server" onrowdatabound="GridView1_RowDataBound" xmlns:asp="#unknown">
    <columns>
        <asp:templatefield>
            <itemtemplate>
               <asp:label id="lbl" runat="server" text=""></asp:label>
            </itemtemplate>
        </asp:templatefield>
    </columns>
</asp:gridview>




您使用的活动还可以。





The event you used is ok.

protected void lr_grid_RowDataBound(object sender, GridViewRowEventArgs e)
       {
           if (e.Row.RowType == DataControlRowType.DataRow)
           {
                //Do your calculations and then assign text to lbl(that is label in templatefield)
           }
       }





对于日期计算,请使用DateTime.Compare方法 [ ^ ]



快乐编码.. :)



For date calculations use DateTime.Compare Method[^]

Happy coding.. :)


使用 [MSDN] DateTime.Compare方法 [ ^ ]。

Use [MSDN] DateTime.Compare Method[^].
引用:

比较 DateTime 的两个实例,并返回一个整数,指示第一个实例是否早于,等于或晚于第二个实例。



参数

t1

类型:System.DateTime

第一个要比较的对象。

t2

类型:System.DateTime

第二个要比较的对象。



返回值

类型 System.Int32

一个有符号的数字,表示t1和t2的相对值。

Compares two instances of DateTime and returns an integer that indicates whether the first instance is earlier than, the same as, or later than the second instance.

Parameters
t1
Type: System.DateTime
The first object to compare.
t2
Type: System.DateTime
The second object to compare.

Return Value
Type: System.Int32
A signed number indicating the relative values of t1 and t2.

Value Type            Condition
Less than zero        t1 is earlier than t2.
Zero                  t1 is the same as t2.
Greater than zero     t1 is later than t2.





这篇关于ASP.Net网格帮助....日期比较问题。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆