views:

56

answers:

2

Edit: more code

Dim oControl As New Forms.Control()

                            Using types As New DataSet
                                With oDal
                                    .Parameters.Clear()
                                    .Execute(sql, types)
                                End With
                                With ddlType
                                    .DataSource = types.Tables(0)
                                    .DataTextField = "Name"
                                    .DataValueField = "TypeId"
                                    .Items.Clear()
                                    .DataBind()
                                    If .Items.Count > 0 Then
                                        .SelectedIndex = 0
                                    End If
                                End With

                            End Using
                            'set queue type with our asp:dropdownlist control
                            oControl = New Forms.Control(Forms.Control.ControlType.ComboBox)
                            'we need to connect the two controls
                            oControl.Id = ddlType.ID

                            'add it to the grid
                            With .Columns.Add("CredentialTypeId", "Type", 85)
                                .Editor = oControl
                            End With

For some reason when you click the dropdown - "0" is displayed defaulted. It needs to be the first text/value pair from the table. The table is only returning one row at the moment, which is correct, but 0 still defaults.

Anyone know why?

+1  A: 
With ddlType
    .DataSource = types.Tables(0)
    .DataTextField = "Name"
    .DataValueField = "TypeId"
    .DataBind()
    If .Items.Count > 0 Then
      .SelectedIndex = 0
    End If
End With

Edit:
Given your results and your comments, I think either your types table is empty or your code isn't being run. Try adding some breakpoints and testing some values.

types.Tables(0) isnot nothing
types.Tables(0).Rows.Count

Edit2:
Looking at your code, I see a different problem. You never fill oControl. I am not sure why you are creating a completely new control and setting it's ID to ddlType's ID. Why don't you just do your databind with oControl? Or attach ddlType to your grid?

Bill
For some reason this isn't working. This is what I tried first. The ddl is within an ExtJS grid if that makes a difference. The DDL is actually a column.
Scott
The table does have data. the Dropdown becomes {0, firstElement}. I just want it to display firstElement instead of 0, and I have NO IDEA how the 0 is even getting there in the first place.
Scott
You were on the right track. My bad. I followed your thought process and eventually found that when the new row was inserted, a javascript method was running and for some reason CHANGING the typeId brought back from the database to the first one. Bad code =/
Scott
A: 

I know this probably won't work but going to say it anyway.

Have you tried to clear all the items before binding the data?

ddType.Items.Clear();
Terry
Doesn't work =/
Scott