Results 1 to 2 of 2

Thread: i need to validate the dates when editing a datagrid

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2002
    Posts
    128

    i need to validate the dates when editing a datagrid

    Hello, i need to validate the DateTime field that is entered when editing data within a datagrid.

    i have a web application written in vb.net

    my datagrid: - aspx

    <aspataGrid
    Runat="Server"
    ID="Datagrid1"
    OnCancelCommand="CancelCommand"
    OnDeleteCommand="DeleteCommand"
    OnUpdateCommand="UpdateCommand"
    OnEditCommand="EditCommand">
    <Columns>
    <asp:TemplateColumn Visible="False"> 'Used as key
    <ItemTemplate>
    <asp:Label ID="lblStartDate" Text='<%# DataBinder.Eval(Container.DataItem,"StartDate") %>' Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>
    <asp:BoundColumn DataField="StartDate"></asp:BoundColumn>
    <asp:BoundColumn DataField="EndDate"></asp:BoundColumn>
    <asp:BoundColumn DataField="Operator"></asp:BoundColumn>
    <asp:EditCommandColumn ItemStyle-Width="120" ButtonType="LinkButton" CancelText="Cancel" EditText="Edit" UpdateText="Update"></asp:EditCommandColumn>
    <asp:TemplateColumn ItemStyle-Width="80" ItemStyle-HorizontalAlign="Center">
    <ItemTemplate>
    <asp:CheckBox ID="chkSelection" Runat="server" />
    </ItemTemplate>
    </asp:TemplateColumn>

    </Columns>
    </aspataGrid>


    my datagrid: - code behind

    Code:
     
        Sub MyDataGrid_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
            dgdBurnOffTimeEdit.EditItemIndex = e.Item.ItemIndex
            tblNotes.Visible = True
            BindData()
        End Sub
        Sub MyDataGrid_Cancel(ByVal Source As Object, ByVal E As DataGridCommandEventArgs)
            dgdBurnOffTimeEdit.EditItemIndex = -1
            BindData()
            tblNotes.Visible = False
        End Sub
        Sub MyDataGrid_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
            Dim tID = dgdBurnOffTimeEdit.DataKeys(CInt(e.Item.ItemIndex))
            Dim tStartDate As TextBox = e.Item.Cells(1).Controls(0)
            Dim tEndDate As TextBox = e.Item.Cells(2).Controls(0)
            Dim tOperator As TextBox = e.Item.Cells(3).Controls(0)
    
            strStart = FormatDateTime(CDate(tStartDate.Text), 1) & " " & FormatDateTime(CDate(tStartDate.Text), 4)
            strEnd = FormatDateTime(CDate(tEndDate.Text), 1) & " " & FormatDateTime(CDate(tEndDate.Text), 4)
            Dim ID = FormatDateTime(CDate(tID), 1) & " " & FormatDateTime(CDate(tID), 4)
    
            Dim MySDate As Date = strStart
            Dim MyEDate As Date = strEnd
    
            Dim ts As TimeSpan = MyEDate.Subtract(MySDate)
            Dim Minutes = ts.TotalMinutes
    
            If Minutes > 5 Then
                Exit Sub
            Else
                ws.Credentials = System.Net.CredentialCache.DefaultCredentials
                ws.BurnOffInsert(strStart, strEnd, tOperator.Text, ID)
    
                dgdBurnOffTimeEdit.EditItemIndex = -1
                BindData()
            End If
            tblNotes.Visible = False
        End Sub
        Sub MyDataGrid_DeleteCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs)
            Dim txtID = dgdBurnOffTimeEdit.DataKeys(CInt(e.Item.ItemIndex))
            Dim ID = FormatDateTime(CDate(txtID), 1) & " " & FormatDateTime(CDate(txtID), 4)
            ws.Credentials = System.Net.CredentialCache.DefaultCredentials
            ws.BurnOffDelete(ID)
            BindData()
        End Sub

  2. #2
    Addicted Member
    Join Date
    Jan 1999
    Posts
    165
    Try looking into making them template columns and go into edit template where you can place a validator against the textbox for the dates.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width