asp bootstrap-select 不工作

asp bootstrap-select not working

asp .net 4.0 使用bootstrap-select时运行后面的代码,下拉列表不显示。但如果不是运行后面的代码,则显示下拉列表。

page.aspx

<asp:DropDownList ID="ddl" runat="server" CssClass="selectpicker" OnSelectedIndexChange="ddlChange" AutoPostBack="true">
</asp:DropDownList>

page.aspx.cs

protected void Page_Load(object sender, EventArgs e)
{
    ddl.Style["display"] = "inline";
    SqlConnection sqlCon = new SqlConnection(ConnectString);
    sqlCon.Open();
    SqlCommand sqlCmd = new SqlCommand("select name from customer", sqlCon);
    SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    ddl.DataSource = dt;
    ddl.DataValueField = "name";
    ddl.DataTextField = "name";
    ddl.DataBind();
    sqlCon.Close();
}

我该如何解决? 谢谢。

protected void Page_Load(object sender, EventArgs e) {
    ddl.Style["display"] = "inline";
    SqlConnection sqlCon = new SqlConnection(ConnectString);
    sqlCon.Open();
    SqlCommand sqlCmd = new SqlCommand("select name from customer", sqlCon);
    SqlDataAdapter da = new SqlDataAdapter(sqlCmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    ddl.DataSource = dt;
    ddl.DataValueField = "name";
    ddl.DataTextField = "name";
    ddl.DataBind();
    sqlCon.Close();
}

好的。从您的评论来看,您可以使用以下内容:

if(dt.Rows.Count>0)
{
    ddl.Visible= true;
}
else
{
   ddl.Visible= false;
}