Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
35
Grid updatecell event throws as error
posted

Hi,

On my sample web form i am using webgrid and webcombo and webcombo is bind to one of the grid column. I am using updatecell event of an ASP.NET grid to update values to DB. I have upgraded my control's to Infragistics 9.1 for CLR 2.0 from 7.3. The code behind updatecell was working fine for 7.3 but  after upgrade i am getting the following error message every time i call the event. I debug though all lines but i am not getting any error.

Error

 Server Error in '/' Application.


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:

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.

Stack Trace:

[NullReferenceException: Object reference not set to an instance of an object.]
   Infragistics.WebUI.UltraWebGrid.UltraWebGrid.UpdateDBRow(UltraGridRow row, UltraGridRow oldRow) +236
   Infragistics.WebUI.UltraWebGrid.UltraWebGrid.ProcessChanges(StateChanges stateChanges, Boolean fireEvents) +1560
   Infragistics.WebUI.UltraWebGrid.UltraWebGrid.RaisePostDataChangedEvent() +161
   System.Web.UI.Page.RaiseChangedEvents() +165
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1485

Object reference not set to an instance of an object.

 

My code File

Public Partial Class TestCombo
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
          
            If Page.IsPostBack = False Then
                Dim dtcity As New DataTable
                dtcity.Columns.Add("CityId", GetType(Int16))
                dtcity.Columns.Add("City", GetType(String))

                dtcity.Rows.Add(New Object() {1, "Nuneaton"})
                dtcity.Rows.Add(New Object() {2, "London"})
                dtcity.Rows.Add(New Object() {3, "Coventry"})

                WebCombo1.DataSource = dtcity
                WebCombo1.DataTextField = "City"
                WebCombo1.DataValueField = "CityId"

                setGrid(1)

            End If

            WebCombo1.Columns(0).Hidden = True

        Catch ex As System.Exception
            Response.Write(ex.Message)
        End Try
    End Sub

    Private Sub setGrid(ByVal cityVal As Int16)
        Try
            Dim dt As New DataTable

            dt.Columns.Add("Name", GetType(String))
            dt.Columns.Add("City", GetType(Int16))

            dt.Rows.Add(New Object() {"Test name", cityVal})

            UltraWebGrid1.DataSource = dt
            UltraWebGrid1.DataBind()

        Catch ex As System.Exception
            Throw ex
        End Try
    End Sub

    Private Sub UltraWebGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles UltraWebGrid1.InitializeLayout
        Try
            With e.Layout.Bands(0)

                .Columns(.Columns.FromKey("City").Index).Type = Infragistics.WebUI.UltraWebGrid.ColumnType.DropDownList
                .Columns(.Columns.FromKey("City").Index).ValueList.WebCombo = WebCombo1

            End With
        Catch ex As System.Exception
            Response.Write(ex.Message)
        End Try
    End Sub

    Private Sub UltraWebGrid1_UpdateCell(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.CellEventArgs) Handles UltraWebGrid1.UpdateCell
        Try
            setGrid(e.Cell.Row.Cells(1).Value)
        Catch ex As System.Exception
            Response.Write(ex.Message)
        End Try
    End Sub

End Class

 

 

Parents
  • 3732
    Suggested Answer
    posted

    Hello,

    The code looks fine. Since you are getting this error after upgrading, I would suggest to change syntax when you are attaching the WebCombo to the WebGridColumn.

    DAB said:

    Private Sub UltraWebGrid1_InitializeLayout(ByVal sender As Object, ByVal e As Infragistics.WebUI.UltraWebGrid.LayoutEventArgs) Handles UltraWebGrid1.InitializeLayout
            Try
                With e.Layout.Bands(0)

                    .Columns(.Columns.FromKey("City").Index).Type = Infragistics.WebUI.UltraWebGrid.ColumnType.DropDownList
                    .Columns(.Columns.FromKey("City").Index).ValueList.WebCombo = WebCombo1

                End With
            Catch ex As System.Exception
                Response.Write(ex.Message)
            End Try
        End Sub

    This following link shows how to do it:

    http://help.infragistics.com/Help/NetAdvantage/ASPNET/2009.1/CLR3.5/html/WebGrid_Display_WebCombo_in_a_Cell.html

    Let me know if the issue still persists after modifying the syntax.

    Thanks,

    Sarita

Reply Children