Adding DDL Edit Column from code behind problem.

  • Thread starter Sam Jenkins via .NET 247
  • Start date
S

Sam Jenkins via .NET 247

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top