need help to set value to combo box in grid

2 posts, 0 answers
  1. Mubasshar
    Mubasshar avatar
    7 posts
    Member since:
    Jul 2011

    Posted 07 Jul 2011 Link to this post

    Dear Friends


    i am using rad combo box while editing my grid . edit and add is working fine only thing what i need is to set the combo box field to the grid column value on edit. but in my case it always showing the first index value in the combo box.
    i am trying to get the grid column value on item command 

    Private Sub HotelGrid_ItemCommand(ByVal source As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles HotelGrid.ItemCommand
            Dim _item As GridEditableItem
            Dim _AreaDesc As TableCell
            Dim _Star As Int32 = 1
            Dim ddl1 As RadComboBox
            '
            If e.CommandName = RadGrid.EditCommandName Then
                Try
                    _item = e.Item
                    _AreaDesc = _item("AreaDesc")
                    ddl1 = DirectCast(_item.FindControl("ddHotelArea"), RadComboBox)
                          ddl1.Text = _AreaDesc.Text.ToString
     
                Catch ex As Exception
                    DisplayMessage(ex.ToString)
                End Try
                 
     
     
     
     
            End If
        End Sub

    When i am trying to assign _AreaDesc.Text to ddl1.text i am getting this error System.NullReferenceException: Object reference not set to an instance of an object.
  2. Princy
    Princy avatar
    17421 posts
    Member since:
    Mar 2007

    Posted 07 Jul 2011 Link to this post

    Hello Mubasshar,

    Try the following code snippet in ItemDataBound event to access the RadComboBox in edit mode.

    VB:
    Protected Sub RadGrid1_ItemDataBound(sender As Object, e As GridItemEventArgs)
        If TypeOf e.Item Is GridEditableItem AndAlso e.Item.IsInEditMode Then
            Dim item As GridEditableItem = DirectCast(e.Item, GridEditableItem)
            Dim combo As RadComboBox = DirectCast(item.FindControl("ddHotelArea"), RadComboBox)
            combo.DataSourceID = "SqlDataSource1"
            combo.DataTextField = ""
            combo.DataValueField = ""
        End If
    End Sub

    Thanks,
    Princy.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top