Pole poleceń z komunikatem
Mam takie pole dowodzenia,
<asp:CommandField ShowEditButton="true" ShowDeleteButton="True" ItemStyle-Width="10px" />
Teraz przy usuwaniu chcę wyświetlić okno potwierdzenia, ale nie jestem pewien, jak mogę to zrobić.
przepraszam, ale nie chcę używać pola szablonu.
Może w jakiś sposób mogę użyć JS do wyświetlenia wiadomości lub może w tym kodzie za metodą,
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
Próbowałem tego,
protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
//In this sample, there are 3 buttons and the second one is Delete button, that's why we use the index 2
//indexing goes as 0 is button #1, 1 Literal (Space between buttons), 2 button #2, 3 Literal (Space) etc.
((Button)e.Row.Cells[0].Controls[2]).OnClientClick = "return confirm('"Do you really want to delete?');";
}
}
ale ja tracę indeks, ponieważ nie ma tam żadnej kontroli.ŹRÓDŁO
Oto pełny kod mojego GridView Zmieniłem nazwy kolumn i innych tekstów, więc nie daj się zwieść,
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" DataKeyNames="UserID" AutoGenerateColumns="false"
CellPadding="5" OnRowDataBound="GridView1_RowDataBound" Width="800px" AllowPaging="True"
PageSize="5" GridLines="Horizontal" OnPageIndexChanging="GridView1_PageIndexChanging"
OnRowCancelingEdit="GridView1_RowCancelingEdit" OnRowDeleting="GridView1_RowDeleting"
OnRowUpdating="GridView1_RowUpdating" OnRowEditing="GridView1_RowEditing">
<Columns>
<asp:TemplateField ItemStyle-Width="8px" ControlStyle-Width="8px">
<ItemTemplate>
<a href="javascript:switchViews('div<%# Eval("UserID") %>', 'one');">
<img id="imgdiv<%# Eval("UserID") %>" alt="Click to show/hide orders" border="0"
src="/_layouts/g1.png" />
</a>
</ItemTemplate>
<AlternatingItemTemplate>
<a href="javascript:switchViews('div<%# Eval("UserID") %>', 'alt');">
<img id="imgdiv<%# Eval("UserID") %>" alt="Click to show/hide orders" border="0"
src="/_layouts/g1.png" />
</a>
</AlternatingItemTemplate>
</asp:TemplateField>
<asp:BoundField DataField="UserID" ReadOnly="true" HeaderText="User ID" ItemStyle-Width="120px" />
<asp:BoundField DataField="Name" HeaderText="User Name" ItemStyle-Width="350px" />
<asp:BoundField DataField="City" HeaderText="City" ItemStyle-Width="800px" />
<asp:CommandField ShowEditButton="true" ShowDeleteButton="True" ItemStyle-Width="10px" />
<asp:TemplateField>
<ItemTemplate>
<tr>
<td colspan="100%">
<div id="div<%# Eval("UserID") %>" style="display: none; position: relative;
left: 25px;">
<asp:GridView ID="GridView2" runat="server" Width="80%" AutoGenerateColumns="false"
DataKeyNames="TTTT" EmptyDataText="There isn't e.">
<Columns>
<asp:HyperLinkField HeaderText="TTTT Title" DataNavigateUrlFields="anotherfield"
DataTextField="TTTT" DataTextFormatString="{0:c}" Target="_blank" />
<asp:BoundField DataField="orDerDescription" HeaderText="orDerDescription" HtmlEncode="False" />
</Columns>
</asp:GridView>
</div>
</td>
</tr>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</ContentTemplate>
</asp:UpdatePanel>
Błąd podczas próby odpowiedzi