我的gridview在每一行都有一个批准按钮,并且可以在点击时批准行,但我想添加一个功能,当用户点击“已批准”时,如果用户确定要批准,则会有一个消息框或确认屏幕请求。这是我的gridview代码,提前谢谢!
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="false" DataKeyNames="TransactionID" OnRowDataBound="GridView1_OnRowDataBound" OnRowCommand="GridView1_RowCommand" CellPadding="4" AllowPaging="true" PageIndex="2" OnPageIndexChanging="GridView1_PageIndexChanging" HeaderStyle-BackColor ="CornflowerBlue" BorderWidth="1" BorderColor="CornflowerBlue" Width="100%" CssClass=" table table-hover" >
<Columns>
<asp:TemplateField>
<HeaderTemplate>
<asp:CheckBox ID="chkHeader" runat="server" />
</HeaderTemplate>
<ItemTemplate>
<asp:CheckBox ID="chkSelect" runat="server" />
</ItemTemplate>
</asp:TemplateField>
<asp:TemplateField>
<ItemTemplate>
<img style="cursor:pointer" src ="../Images/Icons/plus2.png" title="Click to expand and view item/s" />
<asp:Panel ID ="pnlDetails" runat="server" Style="display: none">
<asp:GridView ID="gvDet" runat="server" AutoGenerateColumns="false" CssClass="ChildGrid">
<Columns>
<asp:BoundField ItemStyle-Width="200px" DataField="ItemType" HeaderText="Type" />
<asp:BoundField ItemStyle-Width="250px" DataField="ItemModel" HeaderText="Model" />
<asp:BoundField ItemStyle-Width="140px" DataField="ItemQuantity" HeaderText="Requested Quantity" />
<asp:BoundField ItemStyle-Width="80px" DataField="ItemUnit" HeaderText="Unit" />
<asp:BoundField ItemStyle-Width="100px" DataField="ItemDate" HeaderText="Date Needed" DataFormatString="{0:yyyy-dd-MM}" HtmlEncode="false" />
<asp:BoundField ItemStyle-Width="200px" DataField="ItemDesc" HeaderText="Description" />
<asp:ButtonField ButtonType="Button" CommandName="ApproveRow" HeaderText="Approve" ItemStyle-CssClass="deleteLink" Text="Approve" ControlStyle-CssClass="btn btn-primary" HeaderStyle-ForeColor="White" HeaderStyle-Font-Names="Calibri" ItemStyle-Font-Names="Calibri" />
</Columns>
<HeaderStyle BackColor="CornflowerBlue" />
</asp:GridView>
</ContentTemplate>
<Triggers>
<asp:AsyncPostBackTrigger ControlID="GridView1" EventName="RowCommand" />
</Triggers>
</asp:UpdatePanel>
答案 0 :(得分:0)
尝试此而不是ButtonField列
<asp:TemplateField HeaderText="Approve">
<ItemTemplate>
<asp:Button ID="Button1" runat="server" Text="Approve" CommandName="ApproveRow" OnClientClick="return confirm('Are you sure ?')" />
</ItemTemplate>
</asp:TemplateField>
答案 1 :(得分:0)
您只需将OnClientClick="return confirm('Are you sure you want to delete this event?');"
放入Button HTML
,如下所示:
<asp:ButtonField ButtonType="Button" CommandName="ApproveRow" HeaderText="Approve" ItemStyle-CssClass="deleteLink" Text="Approve" ControlStyle-CssClass="btn btn-primary" HeaderStyle-ForeColor="White" HeaderStyle-Font-Names="Calibri" ItemStyle-Font-Names="Calibri" OnClientClick="return confirm('Are you sure you want to do this event?');" />