asp bootstrap-select不工作

时间:2018-06-18 11:01:30

标签: asp.net twitter-bootstrap-3 bootstrap-select

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();
}

我该如何解决? 谢谢。

2 个答案:

答案 0 :(得分:1)

确定。从您的评论中可以看出,您可以使用以下内容:

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

答案 1 :(得分:0)

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();
}