編輯:更多的代碼如何讓我的下拉列表默認爲第一行名稱表
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