By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,309 Members | 1,452 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,309 IT Pros & Developers. It's quick & easy.

attaching client script to cancel EditCommand in DataGrid

P: n/a
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>

Nov 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Check for ListItemType.EditItem -- this will be the edit row.

-Brock
DevelopMentor
http://staff.develop.com/ballen
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>


Nov 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.