Hi
I have a DetailsView in which I have Edit,Insert and Delete Buttons.If the user clicks on Delete or Insert or Edit, I want to prompt the user by "Are you sure you want to Delete(or edit or Insert),if the user clicks on Yes,then the command is executed,otherwise no
Any help please?
thanks
Dear, friend:
Here is the sample:
<asp:LinkButton ID="DeleteButton" runat="server" CausesValidation="False" CommandName="Delete" Text="Delete" OnClientClick="return confirm('Are you certain you want to delete this product?');"></asp:LinkButton>I hope the above information will be helpful. If you have any issues or concerns, please let me know. It's my pleasure to be of assistance
Well I am using a commandfield for the Delete
<
asp:CommandField ShowDeleteButton="True"ShowEditButton="True"ShowInsertButton="True"/>How can I prompt the user for confirmation?
thanks
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e){ if (e.Row.RowType == DataControlRowType.DataRow) { // reference the Delete LinkButton LinkButton db = (LinkButton)e.Row.Cells[0].Controls[0]; db.OnClientClick = string.Format( "return confirm('Are you certain you want to delete the {0} product?');", product.ProductName.Replace("'", @."\'")); }}ButtonType obj = (ButtonType) e.Row.Cells[commandFieldIndex].Controls[controlIndex];ButtonType is the type of button being used by the CommandField - Button, LinkButton, or ImageButton. By default, the CommandField uses LinkButtons, but this can be customized via the CommandField's
ButtonType property. ThecommandFieldIndex is the ordinal index of the CommandField within the GridView'sColumnscollection, whereas thecontrolIndex is the index of the Delete button within the CommandField'sControlscollection. ThecontrolIndex value depends on the button's position relative to other buttons in the CommandField. For example, if the only button displayed in the CommandField is the Delete button, use an index of 0. If, however, there's an Edit button that precedes the Delete button, use an index of 2. The reason an index of 2 is used is because two controls are added by the CommandField before the Delete button: the Edit button and a LiteralControl that's used to add some space between the Edit and Delete buttons.
No comments:
Post a Comment