开发者

How to get my dropdown to default to first row name in table

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?


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?


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜