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

[Solved] DropDownList in ItemTemplate

1 Answer 178 Views
Grid
This is a migrated thread and some comments may be shown as answers.
rema43001
Top achievements
Rank 1
rema43001 asked on 12 Nov 2009, 04:51 PM

Hello, this is my code for bind a dropdowlist in ItemTemplate that has a Bind("field")

it's work fine, but in Edit Mode one time in     
    list.DataSource = dsDropDown
    give the error:

        {"Object reference not set to an instance of an object."}
   
Then in I'm using a catch for this error, and all is fine.

Do you know a solution for don't use the catch?

  Protected Sub RadGrid1_ItemCreated(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridItemEventArgs) Handles RadGrid1.ItemCreated

    If (TypeOf e.Item Is GridDataItem AndAlso e.Item.IsDataBound) Then

      Try
        Dim dsDropDown As New DataSet()
        OleDbCnn = New Data.OleDb.OleDbConnection(Session("CONNECT_DBS"))
        Dim item As GridDataItem = e.Item
        Dim list As DropDownList = item.FindControl("DDL_AREA_GEOGRAFICA_NAME")
        OleDbSql = Area_Geografica_Code()
        Dim OleDbDad As New Data.OleDb.OleDbDataAdapter
        OleDbDad = New Data.OleDb.OleDbDataAdapter(OleDbSql, OleDbCnn)
        OleDbDad.Fill(dsDropDown)
        list.DataSource = dsDropDown
        list.DataTextField = "NAME"
        list.DataValueField = "CD_CODE"
      Catch ex As Exception
        ex.Message.ToString()
      End Try

    End If

  End Sub

Thanks for any help

1 Answer, 1 is accepted

Sort by
0
Accepted
Pavlina
Telerik team
answered on 13 Nov 2009, 11:32 AM
Hi Richard,

Have you checked out the following help link on how to configure  the GridDropDownColumn. You can either set its ListDataMember property to a  specific Data table  or set the DataSourceID  to a  datasource control. You can also access the DropDownList editor and set its datasource in the ItemDataBound event
Customize/Configure GridDropDownColumn

Best wishes,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
rema43001
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Share this question
or