我有以下的標記:如何在執行SqlDataSource的DeleteCommand時顯示引導模式?
<asp:GridView ID="Users" runat="server"
CssClass="table table-hover table-striped" GridLines="None"
AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" DataKeyNames="Id" DataSourceID="UsersSqlDataSource">
<Columns>
<asp:BoundField DataField="Id" HeaderText="Id" ReadOnly="True" SortExpression="Id" Visible="false" />
<asp:BoundField DataField="UserName" HeaderText="UserName" SortExpression="UserName" />
<asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" />
<asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" />
<asp:BoundField DataField="Email" HeaderText="Email" SortExpression="Email" />
<asp:CommandField ShowEditButton="True" ControlStyle-CssClass="btn btn-info" />
<asp:CommandField ShowDeleteButton="True" ControlStyle-CssClass="btn btn-info" />
</Columns>
</asp:GridView>
<asp:SqlDataSource ID="UsersSqlDataSource" runat="server" ConnectionString="<%$ ConnectionStrings:DefaultConnection %>"
SelectCommand="SELECT [UserName], [Id], [FirstName], [LastName], [Email] FROM [AspNetUsers]"
DeleteCommand="DELETE FROM AspNetUsers WHERE [Id]= @Id"
UpdateCommand="UPDATE AspNetUsers SET FirstName = @FirstName, LastName = @LastName, Email = @Email WHERE (Id = @Id)"></asp:SqlDataSource>
</div>
我沒有任何RowCommand,RowDeleting爲GridView事件。一切都由sql數據源處理。如何在GridView的刪除按鈕被點擊時顯示引導模式確認?
我能夠通過使用RowDataBound事件獲得定期的確認對話框,但不知道如何使用引導模式而不是常規確認?
我添加了一個RowCommand事件對電網和我做了以下內容:
protected void Users_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName == "Delete")
{
var sb = new System.Text.StringBuilder();
sb.Append(@"<script type='text/javascript'>");
sb.Append("$('#deleteModal').modal('show');");
sb.Append(@"</script>");
ScriptManager.RegisterStartupScript(this, this.GetType(), "DeleteModalScript", sb.ToString(), false);
}
}
我有一個SITEMASTER最初曾在底部的腳本,但我無法得到模態時彈出點擊刪除,所以我把腳本放在頂部(Jquery和Bootstrap)。如果可能的話,我寧願他們在底部。
所以,現在我得到的模式彈出,但它仍然刪除記錄,即使我按取消。
是CommandFields's
與Command Name "Delete" and "Edit"
的問題。我是否應該以另一種方式處理刪除和編輯記錄,如asp:ButtonField
?
切換到一個asp:ButtonField的作品,但我現在的問題是JavaScript的底部而不是頂部?
試試這個http://mvcdiary.com/2012/03/11/create-a-jquery-plugin-for-twitter-bootstrap-confirm -modal-popup /或使用https://gist.github.com/trey/1765619 – Amitesh