还添加 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是属性而不是方法
并且不要使用内联样式,创建一个 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>
希望对你有帮助