Hello,
I have a simple WebDataGrid in the page with a TemplateDataField column, which wraps a "delete item" button as ImageButton. I found no answer on the forums or API how to get the current DataKey when using the delete button.
Here is my code:
<%@ Page Title="" Language="C#" MasterPageFile="~/AppMaster.Master" AutoEventWireup="true" CodeBehind="ProjectList.aspx.cs"
Inherits="Web.Modules.Projects.ProjectList" %>
<%@ Register Assembly="Infragistics4.Web.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<%@ Register Assembly="Infragistics35.WebUI.UltraWebGrid.v10.3, Version=10.3.20103.1013, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb"
Namespace="Infragistics.WebUI.UltraWebGrid" TagPrefix="ig" %>
<%@ MasterType VirtualPath="~/AppMaster.Master" %>
<asp:Content ID="headContent" ContentPlaceHolderID="headContentHolder" runat="server">
<script type="text/javascript">
function pageLoad(sender, args)
{
$('input[name*="deleteItem"]').click(function ()
if (window.confirm("Are you sure you want to delete this item?") == false)
return false;
}
else
// HERE I NEED THE DATAKEY
var grid = $.find('<%=pageDataGrid.UniqueID %>');
var activeRow = grid.get_behaviors().get_activation().get_activeCell().get_row();
window.alert(activeRow.get_dataKey());
});
</script>
</asp:Content>
<asp:Content ID="pageActionButtons" ContentPlaceHolderID="pageActionButtonsHolder" runat="server">
<asp:Content ID="pageContent" ContentPlaceHolderID="pageContentHolder" runat="server">
<ig:WebDataGrid ID="pageDataGrid" runat="server" Height="80%" Width="95%" CssClass="grid" DataKeyFields="PRJ_ID" AutoGenerateColumns="false">
<Columns>
<ig:TemplateDataField Key="DeleteItem" Width="75px">
<ItemTemplate>
<asp:ImageButton runat="server" ID="displayItem" AlternateText="Display" ImageUrl="~/Library/Resources/images/itemView.gif"
OnClientClick="" />
<asp:ImageButton runat="server" ID="editItem" AlternateText="Edit" ImageUrl="~/Library/Resources/images/itemEdit.gif"/>
<asp:ImageButton runat="server" ID="deleteItem" AlternateText="Delete" ImageUrl="~/Library/Resources/images/itemDelete.gif" />
</ItemTemplate>
<Header Text="Actions" Tooltip="Actions for items" />
</ig:TemplateDataField>
<ig:BoundDataField DataFieldName="PRJ_ID" Key="PRJ_ID" DataType="System.Int64" Width="10%">
<Header Text="Id" Tooltip="Project Identifier" />
</ig:BoundDataField>
<ig:BoundDataField DataFieldName="DESCR" Key="DESCR" DataType="System.String">
<Header Text="Name" Tooltip="Project name" />
</Columns>
<Behaviors>
<ig:Paging PageSize="20" />
</Behaviors>
</ig:WebDataGrid>
Can anybody help on this?
Thanks
Hi,
Though this is very late reply, could help some one out there.
You can add this function to your script and call it on rowselectionchange event of your webdatagrid.
function onRowSelectionChanged(sender, eventArgs) { var rows = eventArgs.getSelectedRows(); var selectedRow = rows.getItem(0); selectedDataKey = selectedRow.get_dataKey();}
Regards,
Venkatesh
Hi Dave,
it is the a WebDataGrid. The grid variable is initialized in the line above the problematic row:
var grid = $.find('...')
Calin
Hi calinberindea,
It looks as if you may be finding the grid using jQuery or something else. What kind of object is your grid?
regards,Dave
Still not working.
I added <ig:Activation Enabled="true" /> in the Behaviors section and I still get a JS error "Object has no method 'get_behaviors'" at line
Hello calinberindea,
It looks like you need to turn on Activation behavior. Otherwise the active cell cannot be found since the activation behavior will be null on the client.
regards,David Young