473,396 Members | 1,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

attaching client script to cancel EditCommand in DataGrid

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
1 1601
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Stephen | last post by:
I have code which checks whether a datagrid is empty and if it is it shows a panel on my page. If its not empty then Im using the server.transfer to go to another page so as im able to use the...
4
by: Richard Roche | last post by:
Is it possible to use a drop combo instead of a text box when using the EditCommand in the Datagrid? Many table columns are bound to 'lookup' tables, user's don't care about the foreign keys,...
1
by: Learning SQL Server | last post by:
Im trying to modify the Update and Cancel button's style respectively. I have successfully done so to the Edit button but am not sure what the best event is to add the style attribute to. Can...
0
by: Mike | last post by:
I've got an app with a DataTable that gets passed around and modified by datagrids on 3 different asp.net pages. Not all columns need to be displayed, but I need them all in the datagrid so I can...
1
by: bill yeager | last post by:
I'm doing an inline edit of an Admin table using the Datagrid. There are three columns in my Admin table. I want to dynamically disable the corresponding "CareType" field (see below) in the grid...
1
by: Joe | last post by:
Hello All: I have the understanding that the datagrid requires that ViewState be turned on in order to use the ItemCommand, EditCommand,SortCommand, etc event handlers. Does anyone know if this...
1
by: jhcorey | last post by:
I've been googling this and know it's been covered often, but I can't get mine to work. I'm using a dropdown list when editing the record in the datagrid. I'm testing this using an arraylist to...
2
by: andrew.roberts | last post by:
This is my second post now on this subject has I seem to be getting no where and the problem is really starting to bug me now. I can get a datagrid into an editable state but then neither the...
1
by: Andrew Wan | last post by:
Is it possible to make some of the DataGrid functionality to client-side? Such as the Edit, Update, Cancel, Delete functionality? Everytime I click on a row's Edit button, I wait 2 seconds...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.