What is the JavaScript code to change an active cell in WebDataGrid?
This code does not work, but it's all I could find that was anything close to what I need to do:
grid.get_behaviors().get_activation().set_activeCell(1);
Thanks!
Thought I would try one more time to see if anyone wanted to help me with this.
Thanks.
David-
I have been experimenting to do away with the OnCellSelectionChanged event that the grid was using, but I get this error now: "original data source does not support deletes". Since I used a SqlDataSource on the ASPX page, it seems to be looking for the DeleteCommand there, but the delete is actually handled in the code behind. How do I get around that error?
I changed the code to this:
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="sqlOcrZonFile" Height="350px" Width="1390px" DataKeyFields="Customer,Supplier,Ingredient" OnRowsDeleting="WebDataGridView_CellSelectionChanged" OnRowUpdating="WebDataGrid_Row_Updating">
Here's the code behind now:
protected void WebDataGridView_CellSelectionChanged(object sender, Infragistics.Web.UI.GridControls.RowDeletingEventArgs e) {
UInt32 uiResult = TgError.HR_SUCCESS; String sErrorMessage = ""; String sIngredient = ""; String sSupplier = ""; try { // SDH - 042310 - HACK/WATCH // Probably missing some nuance of the grid... // If a user invokes a delete that gets here, and then // refreshes the browser (ie F5), we come back here. // But skips the javascript, and since last pass cleared // the selected cell, that parameter is now null. // For now, expect that it's okay to come here and ignore // an empty cell - until we find some other scenario. // NOTE - Not all refresh fail like this ??? //if (e.CurrentSelectedCells[0] == null) //{ // Global.m_log.LogWarn(m_sLogPrefix + "WebDataGridView_CellSelectionChanged - Ignored CurrentSelectedCells = null"); // // Insure no selection artifacts. // WebDataGrid1.Behaviors.Selection.SelectedCells.Clear(); // goto ExitLabel; //}
//sSupplier = e.CurrentSelectedCells[0].Row.Items[1].Text; //sIngredient = e.CurrentSelectedCells[0].Row.Items[3].Text; sSupplier = e.Row.Items[1].Text; sIngredient = e.Row.Items[3].Text;
#if DEBUG_BUTTON Global.m_log.LogDebug(m_sLogPrefix + "WebDataGridView_CellSelectionChanged"); Global.m_log.LogDebug(" Supplier = " + sSupplier); Global.m_log.LogDebug(" sIngredient = " + sIngredient); #endif
uiResult = MyWebService.DeleteZonFile("WebDataGridView_CellSelectionChanged", TgCriticalSection.CI_THREAD_TIMEOUT_IMMEDIATE, sSupplier, sIngredient, ref sErrorMessage); if (uiResult != TgError.HR_SUCCESS) { lblStatus.Text = "Delete Failed - " + sErrorMessage; lblStatus.ForeColor = System.Drawing.Color.Red; } else { lblStatus.Text = "Delete Complete"; lblStatus.ForeColor = System.Drawing.Color.Black; }
// Insure no selection artifacts. WebDataGrid1.Behaviors.Selection.SelectedCells.Clear();
// Refresh the grid content. WebDataGrid1.Rows.Clear(); WebDataGrid1.DataBind(); } catch (Exception exception) { Global.m_log.LogError("WebDataGridView_CellSelectionChanged - Unexpected Exception = " + exception.Message); lblStatus.Text = "Delete - Unexpected Exception<br/>" + exception.Message; lblStatus.ForeColor = System.Drawing.Color.Red; } // ExitLabel: ; }
Wow, sorry about the aweful formatting when I pasted in my code. I took it right from Visual Studio. Not sure how else to show nicely formatted code in this editor. Please let me know if there is a better way or if you want the code emailed to you.
Thank you David for the fast reply. I tried this, however it selects the cell from the first row and not the current row I am on. What I am trying to accomplish here is a simple JavaScript popup dialog that confirms a deletion of a row. This page was built by someone else and I had to add a new template column to the WebDataGrid. That was pretty straight forward, but by doing that it caused the JavaScript dialog to appear twice (why that happened, I have no idea). The page is working now as expected, but I don't think it is set up correctly for the confirmation dialog. Can you please take a look at the code below and recommend a better way to do this? The developer is using
OnCellSelectionChanged
="WebDataGridView_CellSelectionChanged" to delete the record from the code behind. So basically, the ImageButton from column 1 is selected then the JavaScript is triggered to confirm the delete. If the user selects "OK" then the WebDataGridView_CellSelectionChanged would get launched (that code works correctly). If the user selects "Cancel", then they should be able to select that same ImageButton again to try and delete that row again. Since that cell is already selected, the JavaScript method does not launch. I am not sure if this code in the behaviors section is correct:
<ig:Selection CellSelectType="Single" Enabled="true"> <SelectionClientEvents CellSelectionChanged="WebDataGridView_CellSelectionChanged2" /> </ig:Selection>
Actually, I really don't think the way he handled any of this is correct. To me it would make more sense to call the OnClientClick in the ImageButton which would call the method in the JavaScript. That code would somehow have to call the code behind method to handle the delete?
Please advise as to how this should be done. Hopefully my explanation is clear. If not, let me know what questions you may have. Below is all the code for the ASPX and CS pages:
<%
@ Page Language="C#" AutoEventWireup="true" MasterPageFile="~/TraceGains.master"
CodeFile="ManagePDFTemplates.aspx.cs" Inherits="TraceGains_Main.ManagePDFTemplates"
Title="Manage PDF Templates" %>
@ Register Assembly="Infragistics35.Web.v10.3, Version=10.3.20103.2120, Culture=neutral, PublicKeyToken=7dd5c3163f2cd0cb" Namespace="Infragistics.Web.UI.GridControls" TagPrefix="ig" %>
<
asp:Content ID="ContentHead" ContentPlaceHolderID="head" runat="Server">
<script type="text/javascript">
</script>
<style type="text/css">
.style1
{
width: 35px;
}
.style10
width: 268435488px;
</style>
</
asp:Content>
asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="mainMenuBar" class="sectionBar">
Manage PDF Templates
</div>
<table style="width: 100%; margin-right: 0px;" align="center">
<tr>
<td style="font-family: Arial, Helvetica, sans-serif;" align="left" nowrap="nowrap">
</td>
<td colspan="3" style="padding-right: 40px" align="center">
<asp:Label ID="lblStatus" runat="server" Text="Status" Font-Size="Small"></asp:Label>
<td>
</tr>
</table>
<table width="1100" border="0" cellpadding="2" cellspacing="0">
<td width="10px" align="right"> </td>
<td width="90px" align="right">
<b>
<asp:Label ID="lblSupplier" runat="server" Text="Supplier: " Font-Size="Small" Width="144px"></asp:Label></b>
<td width="268px" align="left">
<asp:DropDownList ID="ddlSupplier" runat="server" TabIndex="1" Width="350px">
</asp:DropDownList>
<asp:Label ID="lblIngredient" runat="server" Text="TraceStation Name: " Font-Size="Small" Width="144px"></asp:Label></b>
<asp:DropDownList ID="ddlIngredient" runat="server" TabIndex="2" Width="350px">
<td align="right">
<asp:Label ID="lblFile" runat="server" Text="File: " Font-Size="Small"></asp:Label></b>
<td align="left">
<asp:FileUpload ID="fuFile" runat="server" TabIndex="3" Width="233px" />
<asp:Label ID="keyPhrase1Lbl" runat="server" Text="Key Phrase 1: " Font-Size="Small" Width="144px"></asp:Label></b>
<asp:TextBox ID="keyPhrase1Txt" runat="server" Width="144px"></asp:TextBox>
<asp:Label ID="keyPhrase2Lbl" runat="server" Text="Key Phrase 2: " Font-Size="Small" Width="144px"></asp:Label></b>
<asp:TextBox ID="keyPhrase2Txt" runat="server" Width="144px"></asp:TextBox>
<asp:Label ID="keyPhrase3Lbl" runat="server" Text="Key Phrase 3: " Font-Size="Small" Width="144px"></asp:Label></b>
<asp:TextBox ID="keyPhrase3Txt" runat="server" Width="144px"></asp:TextBox>
<td align="center" colspan="7">
<asp:Button ID="btnAddZonFile" runat="server" OnClick="btnAddZonFile_Click" TabIndex="0"
Text="Add Template" Width="150px" />
<td colspan="6">
<ig:WebDataGrid ID="WebDataGrid1" runat="server" AutoGenerateColumns="False" DataSourceID="sqlOcrZonFile"
Height="350px" Width="1390px" DataKeyFields="Customer,Supplier,Ingredient"
OnCellSelectionChanged="WebDataGridView_CellSelectionChanged"
OnRowUpdating="WebDataGrid_Row_Updating">
<Columns>
<ig:TemplateDataField Key="DeleteItem" CssClass="Center" Width="30px">
<ItemTemplate>
<asp:ImageButton runat="server" ID="DeleteItem" AlternateText="Delete" ImageUrl="../Images/trashcan.png" />
</ItemTemplate>
</ig:TemplateDataField>
<ig:BoundDataField DataFieldName="Supplier" Key="Supplier" Width="130px">
<Header Text="Supplier ID" />
</ig:BoundDataField>
<ig:TemplateDataField Key="idName" CssClass="Center" Width="130px" Header-Text="Supplier Name">
<asp:Label ID="idNameLbl" runat="server" Text='<%# Eval("idName") %>'></asp:Label>
<Header Text="Supplier Name"></Header>
<ig:BoundDataField DataFieldName="Ingredient" Key="Ingredient" Width="150px">
<Header Text="TraceStation Name" />
<ig:BoundDataField DataFieldName="ZonFilename" Key="ZonFilename" Width="250px">
<Header Text="PDF Template" />
<ig:BoundDataField DataFieldName="KeyPhrase1" Key="KeyPhrase1" Width="130px">
<Header Text="Key Phrase 1" />
<ig:BoundDataField DataFieldName="KeyPhrase2" Key="KeyPhrase2" Width="130px">
<Header Text="Key Phrase 2" />
<ig:BoundDataField DataFieldName="KeyPhrase3" Key="KeyPhrase3" Width="130px">
<Header Text="Key Phrase 3" />
</Columns>
<Behaviors>
<ig:Selection CellSelectType="Single" Enabled="true">
<SelectionClientEvents CellSelectionChanged="WebDataGridView_CellSelectionChanged2" />
</ig:Selection>
<ig:EditingCore>
<ig:CellEditing Enabled="true">
<EditModeActions EnableF2="true" EnableOnActive="true" MouseClick="Single" />
<ColumnSettings>
<ig:EditingColumnSetting ColumnKey="DeleteItem" ReadOnly="true" />
<ig:EditingColumnSetting ColumnKey="Supplier" ReadOnly="true" />
<ig:EditingColumnSetting ColumnKey="Ingredient" ReadOnly="true" />
<ig:EditingColumnSetting ColumnKey="ZonFilename" ReadOnly="true" />
<ig:EditingColumnSetting ColumnKey="KeyPhrase1" ReadOnly="false" />
<ig:EditingColumnSetting ColumnKey="KeyPhrase2" ReadOnly="false" />
<ig:EditingColumnSetting ColumnKey="KeyPhrase3" ReadOnly="false" />
</ColumnSettings>
</ig:CellEditing>
</Behaviors>
</ig:EditingCore>
<ig:ColumnResizing>
</ig:ColumnResizing>
<ig:Activation>
</ig:Activation>
</ig:WebDataGrid>
<td width="100%">
<asp:SqlDataSource ID="sqlOcrZonFile" runat="server" ConnectionString="<%$ ConnectionStrings:LocalConnectionString %>"
SelectCommand="SELECT [Customer], [Supplier], [Ingredient], [ZonFilename], [KeyPhrase1], [KeyPhrase2], [KeyPhrase3], Supplier_Information_WS.[Supplier Name] as idName FROM [OcrZonFile] LEFT JOIN Supplier_Information_WS ON [OcrZonFile].Supplier = Supplier_Information_WS.[Supplier ID] WHERE ([Customer] = @Customer) ORDER BY [Supplier], [Ingredient], [ZonFilename]"
UpdateCommand="Update [OcrZonFile] set KeyPhrase1 = @KeyPhrase1, KeyPhrase2 = @KeyPhrase2, KeyPhrase3 = @KeyPhrase3 WHERE Customer = @Customer and Supplier = @Supplier and Ingredient = @Ingredient">
<SelectParameters>
<asp:Parameter DefaultValue="" Name="Customer" Type="String" />
</SelectParameters>
<UpdateParameters>
<asp:Parameter Name="Customer" Type="String" />
<asp:Parameter Name="Supplier" Type="String" />
<asp:Parameter Name="Ingredient" Type="String" />
<asp:Parameter Name="ZonFilename" Type="String" />
<asp:Parameter Name="KeyPhrase1" Type="String" />
<asp:Parameter Name="KeyPhrase2" Type="String" />
<asp:Parameter Name="KeyPhrase3" Type="String" />
</UpdateParameters>
</asp:SqlDataSource>
function WebDataGridView_CellSelectionChanged2(webDataGrid, evntArgs) {
var grid = $find('<%= WebDataGrid1.ClientID %>');
var selectedColumn = grid.get_behaviors().get_selection().get_selectedCells().getItem(0).get_index()
var index = selectedColumn + 1;
// If not the delete column, just ignore selection.
if (selectedColumn == 0) {
if (confirm("Do you want to delete the PDF Template?")) {
// On confirmation, postback a cell was selected which
// implies delete the related row.
// debugger;
__doPostBack(
'<%= WebDataGrid1.ClientID %>', '');
else {
// grid.get_behaviors().get_selection().get_selectedCells()._unselect();
// grid.get_behaviors().get_activation().set_activeCell(index);
// var newSelectedCell = evntArgs.getSelectedCells().getItem(0);
// var row = newSelectedCell.get_row();
//var job = row.get_cell(5).get_value();
// var setactivecell = grid.get_behaviors().get_activation().set_activeCell(1);
// grid.get_behaviors().get_selection().get_selectedCells().clear();
// var cell = grid.get_rows().get_row(0).get_cell(2);
// grid.get_behaviors().get_activation().set_activeCell(cell);
return;
// Don't leave any cell selected:
// 1) Looks dumb.
// 2) Reclick on same cell won't come back here (no change).
// like delete-cancel-delete again.
// return false;
#define
DEBUG_BUTTON
DEBUG_LOAD
DEBUG_SQL
DEBUG_WEB
using
System;
System.Collections;
System.Configuration;
System.Data;
System.Data.SqlClient;
System.Linq;
System.Web;
System.Web.Security;
System.Web.UI;
System.Web.UI.HtmlControls;
System.Web.UI.WebControls;
System.Web.UI.WebControls.WebParts;
System.Xml.Linq;
TraceGains.Common;
Tables;
Resources;
TraceGains.Views;
namespace
TraceGains_Main
Page
;
].ConnectionString);
log;
.RESX_PS_All;
//------------------------------------------------------------------
// Page_Load
e)
.HR_SUCCESS;
log =
].ToString());
try
))
] = Page.Request.FilePath;
Response.Redirect(
);
/*
if (!Page.IsPostBack)
if ((Session["Role_SA"].ToString().ToUpper() == "TRUE") || (Session["Role_Config"].ToString().ToUpper() == "TRUE"))
// Do Something with PDFs
else
// permission violation
Response.Redirect("Default.aspx");
*/
)
) &&
(Session[
// Get the log prefix string as soon as possible.
m_sLogPrefix =
),
#if
#endif
// Clear the status feedback.
lblStatus.Text =
uiResult =
,
.m_sConfigSqlConnectionString,
sqlConnection,
sErrorMessage);
.HR_SUCCESS)
uiResult,
sErrorMessage); ;
// Get the possible Suppliers...
sSqlCmd =
"SELECT hID, hID + ' - ' + Supplier_Information_WS.[Supplier Name] as idName FROM Resources JOIN Supplier_Information_WS ON Resources.hID = Supplier_Information_WS.[Supplier ID]"
+
" WHERE Resources.Type = 'Supplier' AND Resources.RecordStatus = '1'"
// sSqlCmd = "SELECT " + Tables.Resources.CS_HID + " " +
//"FROM " + Tables.Resources.CS_TABLE + " " +
//"WHERE (" + Tables.Resources.CS_TYPE + " = '" + Tables.Resources.CS_TYPE__SUPPLIER + "') AND " +
// "(" + Tables.Resources.CS_RECORD_STATUS + " = '1') " +
//"ORDER BY " + Tables.Resources.CS_HID + " ASC ";
sqlCmd =
(sSqlCmd,
sqlConnection);
+ sSqlCmd);
sqlDR = sqlCmd.ExecuteReader();
ddlSupplier.Items.Clear();
ddlSupplier.Items.Add(
//ddlSupplier.Items.Add(sqlDR[Tables.Resources.CS_HID].ToString(),sqlDR["idName"]);
// ddlSupplier.Items.Add(sqlDR[Tables.Resources.CS_HID].ToString());
.CS_HID].ToString()));
sqlDR.Close();
// Get the possible Ingredients...
ddlIngredient.Items.Clear();
ddlIngredient.Items.Add(
ddlIngredient.Items.Add(sqlDR[
.CS_TEMPLATE_NAME].ToString());
// PopulateIngredientDropDown();
// Set the grid to use the configured Ocr CustomerName.
sqlOcrZonFile.SelectParameters[
.m_sConfigCustomerName;
exception)
) != 0)
exception.Message);
exception.Message;
lblStatus.ForeColor = System.Drawing.
.Red;
finally
sqlDR.Dispose();
sqlCmd.Dispose();
field1)
cnLocal.Open();
tIngID = field1.ToString();
tIngID = tIngID.Replace(
(tIngID.Length > 0)
tIngName = TgIngredients.
.GetIngredientName(cnLocal, tIngID);
(tIngName.Length > 0)
{ }
tIngName =
cnLocal.Close();
tIngName;
PopulateIngredientDropDown()
, log);
(alValueList.Count > 600)
// Control Change deprecates need to change viewstate.
// Session.Add("RebindIngredients", true);
// ddlViews.EnableViewState = false;
alValueList)
(item.Text, item.Value));
// NOTE no [ ] needed added later... ET-408
// ddlIngredient.Items.Insert(0, new ListItem(all, "AllIngredients_CC"));
// WebDataGridView_CellSelectionChanged
// SDH - 042310 - HACK/WATCH
// Probably missing some nuance of the grid...
// If a user invokes a delete that gets here, and then
// refreshes the browser (ie F5), we come back here.
// But skips the javascript, and since last pass cleared
// the selected cell, that parameter is now null.
// For now, expect that it's okay to come here and ignore
// an empty cell - until we find some other scenario.
// NOTE - Not all refresh fail like this ???
// Insure no selection artifacts.
WebDataGrid1.Behaviors.Selection.SelectedCells.Clear();
ExitLabel;
sSupplier = e.CurrentSelectedCells[0].Row.Items[1].Text;
sIngredient = e.CurrentSelectedCells[0].Row.Items[3].Text;
+ sSupplier);
+ sIngredient);
.CI_THREAD_TIMEOUT_IMMEDIATE,
sSupplier,
sIngredient,
sErrorMessage;
.Black;
// Refresh the grid content.
WebDataGrid1.Rows.Clear();
WebDataGrid1.DataBind();
ExitLabel:
// btnAddZonFile_Click
+ ddlSupplier.Text);
+ ddlIngredient.Text);
+ fuFile.PostedFile.FileName);
ddlSupplier.Text,
ddlIngredient.Text,
fuFile.PostedFile.FileName,
keyPhrase1Txt.Text,
keyPhrase2Txt.Text,
keyPhrase3Txt.Text,
fuFile.FileBytes,
lblStatus.Text = btnAddZonFile.Text +
// WebDataGrid1.ClearDataSource();
// WebDataGrid1.DataSource = sqlOcrZonFile;
// Response.Write("HERE");
Hi claytonAgil,
You need to pass a GridCell object.
var cell = grid.get_rows().get_row(0).get_cell(2);
grid.get_behaviors().get_activation().set_activeCell(cell);
regards,David Young