在CommandField中删除确认消息? [英] Delete Confirmation Message in CommandField?

查看:110
本文介绍了在CommandField中删除确认消息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

删除按钮 GridView 中, 确认消息如果我符合,那么只会在 GridView 中删除该行。

* .ASPX

 <列> 

< asp:CommandField ButtonType =ButtonShowDeleteButton =true/>

< /列>

* .ASPX.CS

  protected void grdPersTable_RowDataBound(object sender,GridViewRowEventArgs e)
{
if(e.RowType == DataControlRowType.DataRow)
{
Button buttonCommandField = e.Row.Cells [0] .Controls [0] as Button;
buttonCommandField.Attributes [onClick] =
string.Format(return confirm('你想删除'));



protected void grdPersTable_RowDeleting(object sender,GridViewDeleteEventArgs e)
{
Label lbl0 =(Label)grdPersTable.Rows [e.RowIndex ] .FindControl( lblId);
txtId.Text = lbl0.Text;
obj.DeleteV(Convert.ToInt32(txtId.Text));
grdPersTable.DataSource = obj.GetTableValues();
grdPersTable.DataBind();
lblMessage.Text =删除成功!;
}


解决方案

p>

 < asp:TemplateField> 
< ItemTemplate>
< asp:Button ID =deletebtnrunat =serverCommandName =Delete
Text =DeleteOnClientClick =return confirm('Are you sure?'); />
< / ItemTemplate>
< / asp:TemplateField>

我将 CommandField 更改为 TemplateField



谢谢!

I am trying get confirmation message while click on delete button in GridView. If I conform only the row will be delete in GridView.

*.ASPX

<Columns>

    <asp:CommandField ButtonType="Button" ShowDeleteButton="true" />

</Columns>

*.ASPX.CS

protected void grdPersTable_RowDataBound(object sender, GridViewRowEventArgs e)
{
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
        Button buttonCommandField = e.Row.Cells[0].Controls[0] as Button;
        buttonCommandField.Attributes["onClick"] = 
               string.Format("return confirm('Are you want delete ')");
    }
}

protected void grdPersTable_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
    Label lbl0 = (Label)grdPersTable.Rows[e.RowIndex].FindControl("lblId");
    txtId.Text = lbl0.Text;
    obj.DeleteV(Convert.ToInt32(txtId.Text));
    grdPersTable.DataSource = obj.GetTableValues();
    grdPersTable.DataBind();        
    lblMessage.Text = "Deleted successfully !";
}

解决方案

I got answer friends

<asp:TemplateField>
      <ItemTemplate>
            <asp:Button ID="deletebtn" runat="server" CommandName="Delete" 
             Text="Delete" OnClientClick="return confirm('Are you sure?');" />
      </ItemTemplate>
</asp:TemplateField>

i changed CommandField to TemplateField

Thanks !

这篇关于在CommandField中删除确认消息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆