Click here to Skip to main content
11,500,106 members (62,843 online)
Rate this: bad
good
Please Sign up or sign in to vote.
See more: ASP.NET
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...

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 13-Nov-12 16:16pm
yenisya329
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

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.
  Permalink  
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

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,,
  Permalink  
v2
Comments
yenisya at 14-Nov-12 2:52am
   
i think i was find the solution...

Thank's for All answer....

Regard's ...
Yeni

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

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 345
1 Maciej Los 290
2 DamithSL 230
3 Peter Leow 181
4 OriginalGriff 167
0 Sergey Alexandrovich Kryukov 335
1 Maciej Los 290
2 DamithSL 220
3 Peter Leow 181
4 OriginalGriff 167


Advertise | Privacy | Mobile
Web04 | 2.8.150520.1 | Last Updated 14 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100