在datagridview Asp.net vb中的DataBound DateTime列中显示null

在datagridview Asp.net vb中的DataBound DateTime列中显示null,asp.net,vb.net,datetime,datagridview,databound,Asp.net,Vb.net,Datetime,Datagridview,Databound,在此处输入代码 Dim objCreditLimits As SCU.DataAccess.Layer.clsCreditLimits=新SCU.DataAccess.Layer.clsCreditLimits Dim objSystemData为SCU.DataAccess.Layer.clsSystemData=新的SCU.DataAccess.Layer.clsSystemData 受保护的子页_LoadComplete(发送者作为对象,e作为System.EventArgs)处理Me.L

在此处输入代码
Dim objCreditLimits As SCU.DataAccess.Layer.clsCreditLimits=新SCU.DataAccess.Layer.clsCreditLimits
Dim objSystemData为SCU.DataAccess.Layer.clsSystemData=新的SCU.DataAccess.Layer.clsSystemData
受保护的子页_LoadComplete(发送者作为对象,e作为System.EventArgs)处理Me.LoadComplete
litMemberID.Text=“-”&Request.QueryString(“MemberID”)
端接头
受保护的子页_PreLoad(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.PreLoad
如果Request.QueryString(“a”)=“注销”,则
会话.放弃()
Response.Redirect(“StaffLogin.aspx”)
如果结束
如果会话(“StaffID”)什么都不是,那么
'Response.Redirect(“StaffLogin.aspx”)
如果结束
端接头
子gvMember_RowDataBound(ByVal sender作为对象,ByVal e作为GridViewRowEventArgs)
'如果e.Row.RowType=DataControlRowType.DataRow,则
'将参数设置为字符串=(“01/01/1900”)。ToString
'DataBinder.Eval(例如Row.DataItem,“EndDate”).ToString()
'如果参数=“01/01/1900”,则
'Dim text As TextBox=DirectCast(e.Row.FindControl(“txtEndDate”),TextBox)
"完"
"完"
端接头
Sub-GVU RowDataBound(ByVal sender作为对象,ByVal e作为GridViewRowEventArgs)
如果e.Row.RowType=DataControlRowType.DataRow,则
将参数设置为字符串=(“01/01/1900”)。ToString
DataBinder.Eval(例如Row.DataItem,“EndDate”).ToString()
如果arguments=“01/01/1900”,则
文本框为文本框=DirectCast(例如,Row.FindControl(“txtEndDate”),文本框)
'text.text=String.Empty
如果结束
如果结束
端接头
'如果e.Row.RowType=DataControlRowType.DataRow,则
'Dim hfDuplicated As HiddenField=CType(e.Row.FindControl(“hfDuplicated”),HiddenField)
'Dim hfSuccessfulBacs As HiddenField=CType(e.Row.FindControl(“hfSuccessfulBacs”),HiddenField)
'Dim lblName As Label=CType(e.Row.FindControl(“lblName”),Label)
'如果e.Row.RowState=DataControlRowState.Normal或LSE e.Row.RowState=DataControlRowState.Alternate,则
'如果是CBool(hfDuplicated.Value),则
'lblName.ForeColor=Drawing.Color.Red
'ElseIf CBool(hfSuccessfulBacs.Value)然后
'lblName.ForeColor=Drawing.Color.Green
"完"
"完"
"完"
受保护的子btnSave\u单击(发件人作为对象,e作为系统.EventArgs)处理btnSave。单击
尝试
Dim memberID为Int64=Request.QueryString(“memberID”)
Dim UserID为整数=会话(“StaffID”)
Dim txtProductAmountLimit作为文本框=无
Dim hfProductAmountLimit As HiddenField=无
Dim txtProductCountLimit作为文本框=无
Dim hfProductCountLimit As HiddenField=无
Dim txtNote As TextBox=无
Dim txtEndDate As TextBox=无
Dim EndDate As Date=“01/01/1900”
Dim Today作为String=Date.Today.ToString(“dd/MM/yyyy”)
Dim lblNoteRequired As Label=无
Dim hfCreditLimitProductID作为HiddenField=无
Dim hfEndDate As HiddenField=无
Dim creditLimit为双精度=0
尺寸年度限制为双精度=0
Dim saveChanges为布尔值=False
Dim noErrors为布尔值=真
lblMessage.Text=“”
对于gvMemberList.Rows中作为GridViewRow的每个gridRow
txtProductAmountLimit=CType(gridRow.Cells(0).FindControl(“txtProductAmountLimit”),文本框)
hfProductAmountLimit=CType(gridRow.Cells(0).FindControl(“hfProductAmountLimit”),HiddenField)
txtProductCountLimit=CType(gridRow.Cells(0).FindControl(“txtProductCountLimit”),文本框)
hfProductCountLimit=CType(gridRow.Cells(0).FindControl(“hfProductCountLimit”),HiddenField)
hfCreditLimitProductID=CType(gridRow.Cells(0.FindControl(“hfCreditLimitProductID”),HiddenField)
txtNote=CType(gridRow.Cells(0).FindControl(“txtNote”),文本框)
txtEndDate=CType(gridRow.Cells(0).FindControl(“txtEndDate”),文本框)
hfEndDate=CType(gridRow.Cells(0).FindControl(“hfEndDate”),HiddenField)
标注日期为日期=“1900年1月1日”
Date.TryParse(IIf(String.IsNullOrEmpty(txtEndDate.Text),“01/01/1900”,txtEndDate.Text),EndD)
如果不是String.IsNullOrEmpty(txtEndDate.Text),也不是Date.TryParse(txtEndDate.Text,EndDate),则
lblMessage.Visible=True
lblMessage.Text=“结束日期无效”
出口接头
如果结束
lblNoteRequired=CType(gridRow.Cells(0).FindControl(“lblNoteRequired”),标签)
Double.TryParse(txtProductAmountLimit.Text,creditLimit)
整数.TryParse(txtProductCountLimit.Text,annualLimit)
如果txtNote.Text.Length=0且为ALSO(creditLimit CDbl(hfProductAmountLimit.Value)或LSE annualLimit CInt(hfProductCountLimit.Value)),则
lblNoteRequired.Visible=True
无错误=错误
lblMessage.Text=“请为您要修改的每个信用额度输入注释”
其他的
lblNoteRequired.Visible=False
如果结束
EndDate=IIf(String.IsNullOrEmpty(txtEndDate.Text),“01/01/1900”,IIf(Date.TryParse(txtEndDate.Text,EndDate),txtEndDate.Text,“01/01/1900”))
如果(txtEndDate.Text.Length=0或Date.Compare(EndD,Today)>0),则
如果txtNote.Text.Length>0且为(creditLimit CDbl(hfProductAmountLimit.Value)或LSE annualLimit CInt(hfProductCountLimit.Value)或LSE IIf(Date.TryParse(txtEndDate.Text,EndD),txtEndDate.Text,“01/01/1900”)CDate(hfEndDate.Value)),则
objCreditLimits.InsertUpdateCreditLimitProduct(memberID、hfCreditLimitProductID.Value、creditLimit、annualLimit、TXNote.Text、EndDate、UserID)
saveChanges=True
如果结束
其他(日期比较(结束,今天)<0)
enter code here

Dim objCreditLimits As SCU.DataAccess.Layer.clsCreditLimits = New SCU.DataAccess.Layer.clsCreditLimits
Dim objSystemData As SCU.DataAccess.Layer.clsSystemData = New SCU.DataAccess.Layer.clsSystemData

Protected Sub Page_LoadComplete(sender As Object, e As System.EventArgs) Handles Me.LoadComplete
    litMemberID.Text = " - " & Request.QueryString("MemberID")
End Sub

Protected Sub Page_PreLoad(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.PreLoad
    If Request.QueryString("a") = "logout" Then
        Session.Abandon()
        Response.Redirect("StaffLogin.aspx")
    End If

    If Session("StaffID") Is Nothing Then
        ' Response.Redirect("StaffLogin.aspx")
    End If
End Sub

Sub gvMember_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)

    'If e.Row.RowType = DataControlRowType.DataRow Then
    '    Dim arguments As String = ("01/01/1900").ToString
    '    DataBinder.Eval(e.Row.DataItem, "EndDate").ToString()
    '    If arguments = "01/01/1900" Then
    '        Dim text As TextBox = DirectCast(e.Row.FindControl("txtEndDate"), TextBox)

    '    End If
    'End If
End Sub

Sub gvBatches_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
    If e.Row.RowType = DataControlRowType.DataRow Then
        Dim arguments As String = ("01/01/1900").ToString
        DataBinder.Eval(e.Row.DataItem, "EndDate").ToString()
        If arguments = "01/01/1900" Then
            Dim text As TextBox = DirectCast(e.Row.FindControl("txtEndDate"), TextBox)
            'text.Text = String.Empty
        End If
    End If
End Sub

'If e.Row.RowType = DataControlRowType.DataRow Then
'    Dim hfDuplicated As HiddenField = CType(e.Row.FindControl("hfDuplicated"), HiddenField)
'    Dim hfSuccessfulBacs As HiddenField = CType(e.Row.FindControl("hfSuccessfulBacs"), HiddenField)
'    Dim lblName As Label = CType(e.Row.FindControl("lblName"), Label)

'    If e.Row.RowState = DataControlRowState.Normal OrElse e.Row.RowState = DataControlRowState.Alternate Then
'        If CBool(hfDuplicated.Value) Then
'            lblName.ForeColor = Drawing.Color.Red
'        ElseIf CBool(hfSuccessfulBacs.Value) Then
'            lblName.ForeColor = Drawing.Color.Green
'        End If
'    End If
'End If





Protected Sub btnSave_Click(sender As Object, e As System.EventArgs) Handles btnSave.Click
    Try
        Dim memberID As Int64 = Request.QueryString("MemberID")
        Dim UserID As Integer = Session("StaffID")
        Dim txtProductAmountLimit As TextBox = Nothing
        Dim hfProductAmountLimit As HiddenField = Nothing
        Dim txtProductCountLimit As TextBox = Nothing
        Dim hfProductCountLimit As HiddenField = Nothing
        Dim txtNote As TextBox = Nothing
        Dim txtEndDate As TextBox = Nothing
        Dim EndDate As Date = "01/01/1900"
        Dim Today As String = Date.Today.ToString("dd/MM/yyyy")

        Dim lblNoteRequired As Label = Nothing
        Dim hfCreditLimitProductID As HiddenField = Nothing
        Dim hfEndDate As HiddenField = Nothing
        Dim creditLimit As Double = 0
        Dim annualLimit As Double = 0
        Dim saveChanges As Boolean = False
        Dim noErrors As Boolean = True
        lblMessage.Text = ""

        For Each gridRow As GridViewRow In gvMemberList.Rows

            txtProductAmountLimit = CType(gridRow.Cells(0).FindControl("txtProductAmountLimit"), TextBox)
            hfProductAmountLimit = CType(gridRow.Cells(0).FindControl("hfProductAmountLimit"), HiddenField)

            txtProductCountLimit = CType(gridRow.Cells(0).FindControl("txtProductCountLimit"), TextBox)
            hfProductCountLimit = CType(gridRow.Cells(0).FindControl("hfProductCountLimit"), HiddenField)

            hfCreditLimitProductID = CType(gridRow.Cells(0).FindControl("hfCreditLimitProductID"), HiddenField)

            txtNote = CType(gridRow.Cells(0).FindControl("txtNote"), TextBox)

            txtEndDate = CType(gridRow.Cells(0).FindControl("txtEndDate"), TextBox)
            hfEndDate = CType(gridRow.Cells(0).FindControl("hfEndDate"), HiddenField)


            Dim EndD As Date = "01/01/1900"
            Date.TryParse(IIf(String.IsNullOrEmpty(txtEndDate.Text), "01/01/1900", txtEndDate.Text), EndD)


            If Not String.IsNullOrEmpty(txtEndDate.Text) AndAlso Not Date.TryParse(txtEndDate.Text, EndDate) Then
                lblMessage.Visible = True
                lblMessage.Text = "Invalid end date"
                Exit Sub
            End If

            lblNoteRequired = CType(gridRow.Cells(0).FindControl("lblNoteRequired"), Label)

            Double.TryParse(txtProductAmountLimit.Text, creditLimit)
            Integer.TryParse(txtProductCountLimit.Text, annualLimit)

            If txtNote.Text.Length = 0 AndAlso (creditLimit <> CDbl(hfProductAmountLimit.Value) OrElse annualLimit <> CInt(hfProductCountLimit.Value)) Then
                lblNoteRequired.Visible = True
                noErrors = False
                lblMessage.Text = "Please enter a note for each credit limit you would like to amend"
            Else
                lblNoteRequired.Visible = False
            End If

            EndDate = IIf(String.IsNullOrEmpty(txtEndDate.Text), "01/01/1900", IIf(Date.TryParse(txtEndDate.Text, EndDate), txtEndDate.Text, "01/01/1900"))


            If (txtEndDate.Text.Length = 0 Or Date.Compare(EndD, Today) > 0) Then


                If txtNote.Text.Length > 0 AndAlso (creditLimit <> CDbl(hfProductAmountLimit.Value) OrElse annualLimit <> CInt(hfProductCountLimit.Value) OrElse IIf(Date.TryParse(txtEndDate.Text, EndD), txtEndDate.Text, "01/01/1900") <> CDate(hfEndDate.Value)) Then

                    objCreditLimits.InsertUpdateCreditLimitProduct(memberID, hfCreditLimitProductID.Value, creditLimit, annualLimit, txtNote.Text, EndDate, UserID)
                    saveChanges = True
                End If

            ElseIf (Date.Compare(EndD, Today) < 0) Then
                lblMessage.Visible = True
                noErrors = False
                lblMessage.Text = "Please enter a furter end date"
                Exit Sub
            End If

        Next

        If saveChanges AndAlso noErrors Then
            odsCreditLimits.Select()
            gvMemberList.DataBind()
        End If



    Catch ex As Exception
        objSystemData.InsertErrorLog(ex, Request.ServerVariables("REMOTE_ADDR"))
        lblMessage.Visible = True
        lblMessage.Text = ex.Message
    End Try
End Sub