This is a migrated thread and some comments may be shown as answers.

need help to set value to combo box in grid

1 Answer 55 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Mubasshar
Top achievements
Rank 1
Mubasshar asked on 08 Jul 2011, 12:53 AM
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.

1 Answer, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 08 Jul 2011, 04:30 AM
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.
Tags
Grid
Asked by
Mubasshar
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Share this question
or