attaching client script to cancel EditCommand in DataGrid

J

js

I have a Datagrid control on my page. I want to attach a client
JavaScript during the control's ItemCreated event in the CodeBehind
like the following, but I can only attach the script to the Edit
command button, but not the Cancel or Update button. Thanks for your
help.

private void ItemsGrid_ItemCreated(object sender,
System.Web.UI.WebControls.DataGridItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item || e.Item.ItemType ==
ListItemType.AlternatingItem)
{
WebControl button = (WebControl)e.Item.Cells[1].Controls[0];
button.Attributes.Add("OnClick", "return confirm(\"Abandoing edit,
are you sure?\");");
}
}

Here is the html of the Datagrid.

<asp:datagrid id="ItemsGrid" runat="server" AllowPaging="True"
DataKeyField="IntegerValue">
<HeaderStyle BackColor="#AAAADD"></HeaderStyle>
<Columns>
<asp:ButtonColumn Text="Delete" ButtonType="PushButton"
CommandName="Delete"/>
<asp:EditCommandColumn ButtonType="PushButton" UpdateText="Update"
HeaderText="Editable" CancelText="Cancel" EditText="Edit"/>
</Columns>
</asp:datagrid>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top