Link to home
Start Free TrialLog in
Avatar of imstac73
imstac73

asked on

Master/Detail Gridview Formview - null error on edit

I have a gridview (gvProjects) and a formview(fvProjects) for the same database table on my web page.  The gridview is used solely for users to view the records. The formview is used for both inserting new records and editing records. The formview is hidden until the user either clicks a button to insert a new record or clicks a link in the gridview to edit the record.

I have entered code in the ItemCreated event of the formview to assign the current date to a field in my table whenever a record is created.  

If I open the formview in Insert mode and either click the Insert button or click the Cancel button, when I try clicking my link in my gridview to open the formview in Edit Mode I get a "Object reference not set to an instance of an object."  when it tries to case the current date.

Not sure why this is doing it because there is a date value in the record.  


And for some reason when I click the Select link on the gridview to edit the record in the Formview it throws a null error form my ItemCreated code.  I don't understand why the ItemCreated event is even being called since I am not inserting but updating.  Also, I'm not sure why it would give me a null error anyway b/c there is data in these fields when the formview goes into Edti Mode.
I have included my formview code and also the ItemCreated code that is throwing the error.  

Any help would be greatly appreciated.
fvprojects_ItemCreated Event:

Protected Sub fvProjects_ItemCreated(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fvProjects.ItemCreated
        'Dim StatusTextBox As TextBox = DirectCast(fvProjects.FindControl("StatusTextBox"), TextBox)
        Dim CreateDateTextBox As TextBox = DirectCast(fvProjects.FindControl("CreateDateTextBox"), TextBox)
        Dim ModifiedDateTextBox As TextBox = DirectCast(fvProjects.FindControl("ModifiedDateTextBox"), TextBox)
        Dim ModifiedByTextbox As TextBox = DirectCast(fvProjects.FindControl("ModifiedByTextBox"), TextBox)

        'StatusTextBox.Text = 1
        CreateDateTextBox.Text = System.DateTime.Now.Date
        ModifiedDateTextBox.Text = System.DateTime.Now.Date
        ModifiedByTextbox.Text = Page.User.Identity.Name.Split("\"c)(1).ToString()


    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Nasir Razzaq
Nasir Razzaq
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of imstac73
imstac73

ASKER

That worked. Thanks so much!