Adding DDL Edit Column from code behind problem.

Discussion in 'ASP .Net Datagrid Control' started by Sam Jenkins via .NET 247, Aug 6, 2004.

  1. Hi,

    I am having a problem with accessing a ddl when editing in my datagrid. I am getting an 'object reference not set to an instance of an object' error.

    Here is some of my code:

    In a custom column class (inheriting template column):

    Sub InitializeCell(..)
    ...
    Dim dd As New DropDownList
    AddHandler dd.DataBinding, AddressOf Me.DD_OnDataBinding
    ...
    Select Case templateType
    Case ListItemType.Item
    ...
    Case ListItemType.EditItem
    Select Case ColumnEditType
    Case ColumnEditType.Textbox
    tb.Text = ""
    cell.Controls.AddAt(0, tb)
    Case ColumnEditType.DropDownList
    cell.Controls.AddAt(0, dd)
    Case ColumnEditType.Checkbox
    cell.Controls.AddAt(0, ck)
    End Select
    End Select

    Then in Sub DD_OnDataBinding:

    Dim dd As DropDownList = CType(sender, DropDownList)
    Dim filePath As String = "xml/" & ExtDetails
    Dim ds As New DataSet
    ds.ReadXml(HttpContext.Current.Server.MapPath(filePath))
    dd.DataTextField = "Description"
    dd.DataValueField = "ID"
    dd.DataSource = ds

    The problem i have is in the UpdateCommand event of the datagrid:
    ...
    Case "System.Web.UI.WebControls.DropDownList"
    Dim dd As DropDownList
    dd = CType(e.Item.Cells(I).Controls(0), DropDownList)
    strValue = dd.SelectedItem.Text
    ...
    The CType works ok but trying to use the properties gives me the object reference error.
    I have tried adding new keywords to both this page and in the template column code, neither having an effect. I am also adding textboxes with the same syntax as i have used to add this ddl and have had no problems in accessing their properties.

    Any help would be most appreciated.

    --------------------------------
    From: Sam Jenkins

    -----------------------
    Posted by a user from .NET 247 (http://www.dotnet247.com/)

    <Id>uFgFF1TQ0E+Lu5vCpqILZA==</Id>
     
    Sam Jenkins via .NET 247, Aug 6, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Ben Miller [msft]

    Re: Code Behind vs. no code behind: error

    Ben Miller [msft], Jun 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    656
    Alphonse Giambrone
    Jun 28, 2003
  2. Shane O. Pinnell

    Databound DDL in Datagrid using code-behind

    Shane O. Pinnell, Jul 10, 2003, in forum: ASP .Net
    Replies:
    0
    Views:
    391
    Shane O. Pinnell
    Jul 10, 2003
  3. San Diego Guy
    Replies:
    0
    Views:
    588
    San Diego Guy
    Aug 7, 2003
  4. Marina
    Replies:
    0
    Views:
    952
    Marina
    Aug 12, 2003
  5. Shane O. Pinnell

    Databound DDL using code-behind

    Shane O. Pinnell, Jul 10, 2003, in forum: ASP .Net Datagrid Control
    Replies:
    0
    Views:
    125
    Shane O. Pinnell
    Jul 10, 2003
Loading...

Share This Page