编辑:更多的代码如何让我的下拉列表默认为第一行名称表
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
出于某种原因,当你点击下拉 - “0”显示拖欠。它需要是表格中的第一个文本/值对。该表仅在此时返回一行,这是正确的,但0仍然是默认值。
任何人都知道为什么?
我很困惑,如果只返回一条记录,它如何默认为0?这个记录是否等于0?是否有更多的代码我们没有看到? – VoltaicShock 2010-09-08 14:35:27
该记录不等于零。我不知道为什么会发生这种情况。这几乎就好像'0'被添加到下拉菜单中作为第一项,它正在成为默认值。我尝试手动设置默认的项目(0),这没有做任何事情,项目(1),这是错误的。 – Scott 2010-09-08 14:37:19
是的,我通常有一个方法,将默认值添加到下拉列表中,所以我有东西要测试以查看用户是否选择了任何内容。 – VoltaicShock 2010-09-08 14:56:09