【问题标题】:Bootstrap Modal Popup引导模式弹出窗口
【发布时间】:2016-09-10 08:54:23
【问题描述】:

我有一个引导模式弹出窗口,它将数据绑定到 asp.net 下拉列表(在模式内部)。现在我想将选定的值保存到数据库中。我的问题是下拉列表的选定值未在 aspx.cs(代码隐藏)页面中传递。

【问题讨论】:

  • 它是一个带有 runat="server" 的 aspx 控件吗?贴一些代码
  • 你能显示一点代码吗?
  • 是的,它是一个带有runat="server"的aspx控件

标签: c# asp.net popup modal-dialog


【解决方案1】:

很难说问题出在哪里,因为您没有在您的问题中发布任何代码,所以这里是一个完整的 Bootstrap 模式弹出窗口中的 DropDownList 控件的工作示例,希望对您有所帮助。

背后的代码:

protected void Page_Load(object sender, EventArgs e)
{
    if(!Page.IsPostBack)
    {
        ddlFood.Items.Add(new ListItem { Text = "Fruits", Value = "1" });
        ddlFood.Items.Add(new ListItem { Text = "Vegetables", Value = "2" });
        ddlFood.Items.Add(new ListItem { Text = "Meat", Value = "3" });
    }
}

protected void btnDone_Click(object sender, EventArgs e)
{
    System.Diagnostics.Debugger.Break();
    string favFood = ddlFood.SelectedItem.Text;
}

.ASPX:

<head runat="server">
    <title></title>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.3/jquery.min.js"></script>
    <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />
</head>
<body>
    <form id="form1" runat="server">
        <button type="button" data-toggle="modal" data-target="#myModal">Launch modal</button>
        <div id="myModal" class="modal fade">
            <div class="modal-dialog">
                <div class="modal-content">
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                        <h4 class="modal-title" id="myModalLabel">Modal Header</h4>
                    </div>
                    <div class="modal-body">
                        Please select your favourite food group:<br />
                        <asp:DropDownList ID="ddlFood" runat="server"></asp:DropDownList><br />
                        <asp:Button ID="btnDone" runat="server" Text="Done" OnClick="btnDone_Click" />
                    </div>
                    <div class="modal-footer">
                        <button type="button" class="btn btn-primary" data-dismiss="modal">Close</button>
                    </div>
                </div>
            </div>
        </div>
    </form>
</body>

【讨论】:

  • 嗨,丹尼斯,谢谢,您的示例正在运行。我在我的代码中实现了它,但是我的 dropDrown 可以传递 dropDown Items 的第一项。它不能将任何其他项目传递给页面后面的代码。那么,有什么建议吗?
  • 您需要将填充 DDL 的代码包装在 if(!Page.IsPostBack){} 中,将我的示例原样复制到一个新的 .aspx 页面中并对其进行测试,您将看到它可以工作。一旦您完成此操作相应地调整您的代码以使其正常工作
【解决方案2】:

您在页面加载方法中绑定下拉列表的位置?在 aspx.cs 中编写如下代码

private void Page_Load()
    {
        if (!IsPostBack)
        {
            // dropdown bind code
            // OR
            // call dropdown bind function eg. bindDropdown();        
        }
    }

bootstrap的model弹窗没有问题

【讨论】:

  • 是的,下拉数据在页面加载时被绑定,就像您在代码@Adhik 中显示的那样
猜你喜欢
  • 1970-01-01
  • 2015-02-16
  • 1970-01-01
  • 1970-01-01
  • 2015-07-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多