添加ValueField也:
Sub DGDataBind()
Dim adapter As Data.SqlClient.SqlDataAdapter
adapter = New Data.SqlClient.SqlDataAdapter("LoadSomething", connection)
adapter.SelectCommand.CommandType = Data.CommandType.StoredProcedure
Dim param As New Data.SqlClient.SqlParameter("@something1", Data.SqlDbType.Bit)
param.Value = 1
adapter.SelectCommand.Parameters.Add(param)
param = New Data.SqlClient.SqlParameter("@something2", Data.SqlDbType.Bit)
param.Value = 0
adapter.SelectCommand.Parameters.Add(param)
GlobalVariables.datas.Clear() 'Public Class GlobalVariables Public Shared datas As New Data.DataSet
adapter.Fill(GlobalVariables.datas)
DDL1.DataSource = GlobalVariables.datas.Tables(0)
DDL1.DataTextField = "rptname"
DDL1.DataValueField = "ColumnName"
DDL1.DataBind()
DDL1.Items.Insert(0, New ListItem("empty", "0"))
DDL1.SelectedIndex = 0
DDL2.DataSource = GlobalVariables.datas.Tables(0)
DDL2.DataTextField = "rptname"
DDL2.DataValueField = "ColumnName"
DDL2.DataBind()
End Sub
和頁面加載應該是這樣的:
If Not IsPostBack Then
DGDataBind()
End If
這裏的問題是在你的代碼: 作爲的IsPostBack是屬性不是方法
並且不使用內聯樣式,crea然後用一個css類來使用它。如下圖所示:
CSS代碼:
<style>
.ddl1
{
font-size: 12px;
color: #0066cc;
font-family: Tahoma;
direction: rtl;
width=100px;
}
</style>
和HTML代碼是:
<asp:DropDownList ID="DDL1" CssClass="ddl1" runat="server">
</asp:DropDownList>
希望這將幫助你
爲什麼您的DDL2下拉列表最後沒有結束標記或「/>」? – hallie
不好意思忘了加剩下的!感謝和問題eddited @hallie – Sijav
我沒有看到與代碼和HTML設置的任何問題。您是否嘗試過調試頁面或按鈕點擊代碼? – hallie