Click here to Skip to main content
15,921,276 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello...
Anyone pleas help me, i got a problem in Gridview Row Updating...

Server Error in '/Timesheet' Application.
Object reference not set to an instance of an object.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.NullReferenceException: Object reference not set to an instance of an object.

Source Error:


Line 160:
Line 161:            'update the timesheet
Line 162:            UpdateTimesheet(id, ddlproject.SelectedValue, ddlactivity.SelectedValue, ddlphase.SelectedValue, ddllocation.SelectedValue, ddlbillable.SelectedValue, txtstar.Text, txtend.Text, txtremark.Text, ddlcustomer.SelectedValue)
Line 163:
Line 164:            'Reset Gridview

Source File: D:\Timesheet\Form\TimesheetEntry.aspx.vb    Line: 162

Stack Trace:


[NullReferenceException: Object reference not set to an instance of an object.]
   TimesheetEntry.GridView1_RowUpdating(Object sender, GridViewUpdateEventArgs e) in D:\Timesheet\Form\TimesheetEntry.aspx.vb:162
   System.Web.UI.WebControls.GridViewUpdateEventHandler.Invoke(Object sender, GridViewUpdateEventArgs e) +0
   System.Web.UI.WebControls.GridView.OnRowUpdating(GridViewUpdateEventArgs e) +133
   System.Web.UI.WebControls.GridView.HandleUpdate(GridViewRow row, Int32 rowIndex, Boolean causesValidation) +720
   System.Web.UI.WebControls.GridView.HandleEvent(EventArgs e, Boolean causesValidation, String validationGroup) +704
   System.Web.UI.WebControls.GridView.OnBubbleEvent(Object source, EventArgs e) +95
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.GridViewRow.OnBubbleEvent(Object source, EventArgs e) +123
   System.Web.UI.Control.RaiseBubbleEvent(Object source, EventArgs args) +37
   System.Web.UI.WebControls.LinkButton.OnCommand(CommandEventArgs e) +118
   System.Web.UI.WebControls.LinkButton.RaisePostBackEvent(String eventArgument) +135
   System.Web.UI.WebControls.LinkButton.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
   System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
   System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +175
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1565


Version Information: Microsoft .NET Framework Version:2.0.50727.5456; ASP.NET Version:2.0.50727.5456


This error i find when i use code
'GridView1.EditIndex = -1

it 's for refresh gridview edit index....
I use this code in row updating function...

VB
Dim id As String = GridView1.DataKeys(e.RowIndex).Value.ToString()

            ' Get the GridViewRow object that represents the row being edited
            ' from the Rows collection of the GridView control.
            Dim row As GridViewRow = GridView1.Rows(e.RowIndex)

            ' Get the controls that contain the updated values. In this
            ' example, the updated values are contained in the TextBox
            ' controls declared in the edit item templates of each TemplateField
            ' column fields in the GridView control.
            Dim txtdate As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtdate"), TextBox)
            Dim ddlproject As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlproject"), DropDownList)
            Dim ddlactivity As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlactivity"), DropDownList)
            Dim ddlphase As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlphase"), DropDownList)
            Dim ddllocation As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddllocation"), DropDownList)
            Dim ddlbillable As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlbillable"), DropDownList)
            Dim txtstar As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtstar"), TextBox)
            Dim txtend As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtend"), TextBox)
            Dim txtremark As TextBox = DirectCast(GridView1.Rows(e.RowIndex).FindControl("txtremark"), TextBox)
            Dim ddlcustomer As DropDownList = DirectCast(GridView1.Rows(e.RowIndex).FindControl("ddlcustomer"), DropDownList)


            'update the timesheet
            UpdateTimesheet(id, ddlproject.SelectedValue, ddlactivity.SelectedValue, ddlphase.SelectedValue, ddllocation.SelectedValue, ddlbillable.SelectedValue, txtstar.Text, txtend.Text, txtremark.Text, ddlcustomer.SelectedValue)

            'Reset Gridview
        'GridView1.EditIndex = -1
            bindData3(Label19.Text)
            'GridView1.DataBind()


I hope anyone help me...
Thank's....
Posted

can you post your grid-view creation code please,
i think there might be some mistake in the fields name,

cause usually this error is when you try to select a data from the gridview that dose not exist !! for example by selecting a wrong row of column,,
 
Share this answer
 
v2
Comments
yenisya 14-Nov-12 2:52am    
i think i was find the solution...

Thank's for All answer....

Regard's ...
Yeni
Check that any parameter in function "UpdateTimesheet()" is null , any one object parameter not initialized may be due to not found in gridview controls etc.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900