简体   繁体   English

Bootstrap Modal 不适用于 asp.net Web 应用程序

[英]Bootstrap Modal not working with asp.net web application


So, I have a web form in asp.net. 所以,我在asp.net 中有一个Web 表单。 On that web form, there is a GridView. 在该 Web 表单上,有一个 GridView。 When the user clicks the view details on gridview, I want a modal popup to show the list of stores in that category. 当用户单击 gridview 上的视图详细信息时,我想要一个模式弹出窗口来显示该类别中的商店列表。 I have been trying different stuff but the modal does not show up. 我一直在尝试不同的东西,但模式没有出现。 Below is my code for front end: 下面是我的前端代码:
 <asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager> <asp:UpdatePanel ID="UpdatePanel1" runat="server"> <ContentTemplate> <div id="DetailsModal" class="modal fade" role="dialog"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <asp:Label ID="lblHead" runat="server" Text="List of stores:" CssClass="h4"></asp:Label> </div> <div class="modal-body"> <asp:Table ID="tblJobs" runat="server" CssClass="tblStoresView" GridLines="Both" CellPadding="6" CellSpacing="6" Visible="False"> <asp:TableRow runat="server"> <asp:TableCell runat="server"> <asp:Label ID="Label1" runat="server" Text="Store Name"></asp:Label> </asp:TableCell> <asp:TableCell runat="server"> <asp:Label ID="lblPost" runat="server" Text=""></asp:Label> </asp:TableCell> </asp:TableRow> <asp:TableRow runat="server"> <asp:TableCell runat="server"> <asp:Label ID="Label2" runat="server" Text="Floor"></asp:Label> </asp:TableCell> </asp:TableRow> <asp:TableRow runat="server"> <asp:TableCell runat="server"> <asp:Label ID="Label5" runat="server" Text="Store number"></asp:Label> </asp:TableCell> <asp:TableCell runat="server"> <asp:Label ID="lblType" runat="server" Text=""></asp:Label> </asp:TableCell> </asp:TableRow> </asp:Table> </div> <div class="modal-footer"> <asp:Button ID="BtnView" CssClass="button" runat="server" Text="View" Visible="False" OnClick="BtnView_Click" /> </div> </div> </div> </div> </ContentTemplate> </asp:UpdatePanel>

I am trying to view the modal on grid's selectindexchanged event. 我正在尝试查看网格的 selectindexchanged 事件上的模式。 The code I am using is as follows: 我使用的代码如下:
 protected void gridStores_SelectedIndexChanged(object sender, EventArgs e) { tblStores.Visible = true; BtnView.Visible = true; GridViewRow row = gridStores.SelectedRow; conn = new SqlConnection(); conn.ConnectionString = connString; sqlcmd = conn.CreateCommand(); string query = "select * from [stores] where cat = @cat"; sqlcmd = new SqlCommand(query, conn); sqlcmd.Parameters.AddWithValue("@cat", row.Cells[1].Text); conn.Open(); da = new SqlDataAdapter(sqlcmd); ds = new DataSet(); da.Fill(ds, "StoresProject"); dt = ds.Tables[0]; foreach (DataRow dr in dt.Rows) { lblName.Text = dr["store name"].ToString(); lblFloow.Text = dr["floor"].ToString(); lblNumber.Text = dr["store number"].ToString(); } }

Can someone please tell me why the modal popup is not showing up? 有人可以告诉我为什么模态弹出窗口没有出现吗? What am i doing wrong? 我究竟做错了什么? Any help will be highly appreciated. 任何帮助将不胜感激。 Thanks! 谢谢!

UPDATE: I tried to display the modal without any grid and backend C# code, by using the simple template from W3Schools.更新:我尝试使用来自 W3Schools 的简单模板,在没有任何网格和后端 C# 代码的情况下显示模态。 The modal still does not popup at all.模态仍然完全没有弹出。

So I solved my problem.所以我解决了我的问题。 It occurred to me that if I enter $(#DetailsModal).modal() in the console window of chrome, the modal appears.$(#DetailsModal).modal() ,如果我在 chrome 的控制台窗口中输入$(#DetailsModal).modal() ,就会出现模态。 So I should try calling it the same way in my site.所以我应该尝试在我的网站中以相同的方式调用它。
So, I wrote a javascript function at the end of my page:所以,我在我的页面末尾写了一个 javascript 函数:

<script>

        function openModal(){
        $('#DetailsModal').modal();
        }

    </script>

And in the code-behind I called by using: 在代码隐藏中,我使用以下方法调用:
 ScriptManager.RegisterStartupScript(this.Page, this.GetType(), "script", "openModal();", true);

And then after that when I tried opening the modal, it appeared correctly with the correct data.然后当我尝试打开模态时,它以正确的数据正确显示。
Thanks to everyone who took time out of their schedule to give suggestions.感谢所有抽出时间提出建议的人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM