Asp.net 当SqlDataSource';是否执行Deletes命令?
我有以下标记:Asp.net 当SqlDataSource';是否执行Deletes命令?,asp.net,gridview,twitter-bootstrap-3,sqldatasource,Asp.net,Gridview,Twitter Bootstrap 3,Sqldatasource,我有以下标记: <asp:GridView ID="Users" runat="server" CssClass="table table-hover table-striped" GridLines="None" AutoGenerateColumns="False" AllowPaging="True" AllowSorting="True" DataKeyNames="Id" DataSourceID="UsersSql
<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,RowView正在删除事件。一切都由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);
}
}
受保护的无效用户\u行命令(对象发送方,GridViewCommandEventArgs e)
{
如果(如CommandName==“删除”)
{
var sb=new System.Text.StringBuilder();
某人加上(@“);
sb.追加($('#deletemodel').model('show'););
某人加上(@“);
ScriptManager.RegisterStartupScript(this,this.GetType(),“DeleteModalScript”,sb.ToString(),false);
}
}
我有一个SiteMaster,它最初在底部有脚本,但我在单击delete时无法获得弹出的模式,所以我将脚本放在顶部(Jquery和Bootstrap)。如果可能的话,我更希望他们在底部
所以现在我得到了弹出的模式,但它仍然删除记录,即使我按下取消
CommandFields的
命令名为“Delete”和“Edit”是问题所在。我是否应该以另一种方式处理删除和编辑记录,例如asp:ButtonField
切换到asp:ButtonField是可行的,但我现在的问题是底部的javascript而不是顶部的javascript?我使用了一个usercontrol来封装我的技术(对不起VB)。基本上,我将对话框href中的确认按钮设置为gridview命令的原始href 标记:
函数(发送方,n){
$(文档).ready(函数()
{
$('#Confirm').attr('href',sender.href);
$(“#Body”).html(函数(){
返回$(this.html().replace(“{0}”,n);
});
$('#').modal('show');
});
返回false;
}
&时代;接近
接近
代码隐藏:
部分类控件\u ConfirmModal
继承System.Web.UI.UserControl
私有m_BodyTemplate作为ITemplate=无
私有m_按钮类为String=“btn btn primary”
公共属性ButtonClass()作为字符串
得到
返回m_按钮类
结束
设置(ByVal值作为字符串)
m_按钮类=值
端集
端属性
私有m_主体为String=“”
作为字符串的公共属性体()
得到
返回m_体
结束
设置(ByVal值作为字符串)
m_Body=值
端集
端属性
私有m_confirButtonText为String=“Confirm”
公共属性confirButtonText()作为字符串
得到
返回m_confirButtonText
结束
设置(ByVal值作为字符串)
m_confirButtonText=值
端集
端属性
私有m_标题为String=“模态标题”
公共属性Title()作为字符串
得到
返回m_标题
结束
设置(ByVal值作为字符串)
m_Title=值
端集
端属性
受保护的子页_Init(ByVal sender作为对象,ByVal e作为System.EventArgs)处理Me.Init
如果不是(Me.BodyTemplate什么都不是),那么
将容器变暗为新的BodyContainer(“”)
Me.BodyTemplate.instanceEIN(容器)
pBody.Controls.Add(容器)
其他的
变暗显示为新的文字控制
display.Text=“”&Me.Body&“”
pBody.Controls.Add(显示)
如果结束
端接头
公共属性BodyTemplate()作为ITemplate
得到
返回m_BodyTemplate
结束
设置(ByVal值作为ITemplate)
m_BodyTemplate=值
端集
端属性
公共级集装箱
继承控制权
容器中的工具
私有m_体作为字符串
Friend Sub New(ByVal正文作为字符串)
身体
端接头
作为字符串的公共属性体()
得到
返回m_体
结束
设置(ByVal值作为字符串)
m_Body=值
端集
端属性
末级
末级
用法1(简单)
在第页某处:
<ics:ConfirmModal runat="server" ID="ArchiveConfirmModal" Title="Archive Campaign?" ConfirmButtonText="Archive" Body="Are you sure you wish to archive the campaign: {0}" ></ics:ConfirmModal>
<ics:ConfirmModal runat="server" ID="DeleteConfirmModal" Title="Delete Campaign?" ConfirmButtonText="Delete" ButtonClass="btn btn-danger" >
<BodyTemplate>
<p>Are you sure you wish to delete <strong>{0}</strong>? This cannot be undone!</p>
<p class="text-muted">This will also remove any associated autoresponders and any scheduled sends will fail.</p>
</BodyTemplate>
</ics:ConfirmModal>
在gridview中:
<asp:LinkButton runat="server" Text="Archive" CommandName="Update" OnClientClick="return ArchiveConfirmModal(this)"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Delete" ToolTip="Delete" CommandName="Delete" OnClientClick=<%# Eval("CampaignName", "return DeleteConfirmModal(this,""{0}"");") %> CssClass="glyphicon glyphicon-remove" ></asp:LinkButton>
用法2(高级)
在第页某处:
<ics:ConfirmModal runat="server" ID="ArchiveConfirmModal" Title="Archive Campaign?" ConfirmButtonText="Archive" Body="Are you sure you wish to archive the campaign: {0}" ></ics:ConfirmModal>
<ics:ConfirmModal runat="server" ID="DeleteConfirmModal" Title="Delete Campaign?" ConfirmButtonText="Delete" ButtonClass="btn btn-danger" >
<BodyTemplate>
<p>Are you sure you wish to delete <strong>{0}</strong>? This cannot be undone!</p>
<p class="text-muted">This will also remove any associated autoresponders and any scheduled sends will fail.</p>
</BodyTemplate>
</ics:ConfirmModal>
是否确实要删除{0}?这是无法撤消的
这也将删除任何关联的自动应答器,并且任何预定发送都将失败
在gridview中:
<asp:LinkButton runat="server" Text="Archive" CommandName="Update" OnClientClick="return ArchiveConfirmModal(this)"></asp:LinkButton>
<asp:LinkButton runat="server" Text="Delete" ToolTip="Delete" CommandName="Delete" OnClientClick=<%# Eval("CampaignName", "return DeleteConfirmModal(this,""{0}"");") %> CssClass="glyphicon glyphicon-remove" ></asp:LinkButton>
尝试此方法或使用