2017-11-16 7 views
0

私はASP C#VS 2015を使用しています.MySQLからのデータでgridviewを生成することができました。 updateとdeleteコマンドはリンクとして表示され、イベントに適切に接続することができました。ASP C#Gridviewでテキストメッセージの削除とプロンプトを確認する

削除する前に確認のメッセージとメッセージ(テキストボックス)を追加する機能を追加したいと思いますか?

.NETでどうすればいいですか?

私はPHPとjQueryに精通していますが、.NETではまだ学習曲線にあります。 ありがとうございます。

<asp:GridView ID="GridView1" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="id" 
      OnRowDataBound="OnRowDataBound" OnRowEditing="OnRowEditing" OnRowCancelingEdit="OnRowCancelingEdit" 
      OnRowUpdating="OnRowUpdating" EmptyDataText="No records has been added." OnRowDeleting="OnRowDeleting" OnRowDeleted="OnRowDeleted"> 
    <Columns> 
     <asp:TemplateField HeaderText="Id" ItemStyle-Width="20"> 
      <ItemTemplate> 
       <asp:Label ID="lblId" runat="server" Text='<%# Eval("id") %>'></asp:Label> 
      </ItemTemplate> 
      <ItemStyle Width="20px"></ItemStyle> 
     </asp:TemplateField> 
     <asp:TemplateField HeaderText="Email"> 
      <ItemTemplate> 
       <asp:Label ID="lblEmail" runat="server" Text='<%# Eval("email") %>'></asp:Label> 
      </ItemTemplate> 
     </asp:TemplateField> 
     <asp:CommandField ShowEditButton="True" ShowDeleteButton="True" DeleteText="Reject" headertext="Controls"></asp:CommandField> 
    </Columns> 
</asp:GridView> 
+0

が重複する可能性を試してみてください[ASP.Net GridViewの中にオプションを "削除の確認" を追加する方法?](https://stackoverflow.com/questions/4793955/how- asp-net-gridviewで削除確認オプションを追加するオプション) – AsifAli72090

答えて

0

のこの

protected void OnRowDataBound(object sender, GridViewRowEventArgs e) 
{ 
    if (e.Row.RowType == DataControlRowType.DataRow) 
    { 
     string item = e.Row.Cells[0].Text; 
     foreach (Button button in e.Row.Cells[2].Controls.OfType<Button>()) 
     { 
      if (button.CommandName == "Delete") 
      { 
       button.Attributes["onclick"] = "if(!confirm('Do you want to delete " + item + "?')){ return false; };"; 
      } 
     } 
    } 
} 
関連する問題