Hi,
I have a webdatatree that control data selection on grid base on ID (department_id).
My problem is when user edit a cell but did not click save, click on another cell and then select another node on the tree I will get this error:
how can I avoid this error and prompt the user if the grid is dirty to save or to continue to another node without saving?
Thanks
Zaid
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: Infragistics.Web.UI.GridControls.MissingRecordException: Requested record cannot be found by key.Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[MissingRecordException: Requested record cannot be found by key.] Infragistics.Web.UI.GridControls.EditingCore.OnAction(String actionType, Object id, Object value, Object tag) +1039 Infragistics.Web.UI.GridControls.GridBehavior.Infragistics.Web.UI.GridControls.IGridBehavior.OnAction(String actionType, Object id, Object value, Object tag) +48 Infragistics.Web.UI.GridControls.GridBot.LoadAdditionalClientState(Object state) +1318 Infragistics.Web.UI.Framework.RunBot.HandleRaisePostDataChangedEvent() +204 Infragistics.Web.UI.GridControls.GridBot.HandleRaisePostDataChangedEvent() +73 Infragistics.Web.UI.Framework.Data.FlatDataBoundControl.RaisePostDataChangedEvent() +37 System.Web.UI.Page.RaiseChangedEvents() +134 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +5201
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm3.aspx.cs" Inherits="voltsweb2.WebForm2" %>
<%@ Register src="WebUserControl1.ascx" tagname="WebUserControl1" tagprefix="uc1" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> <title></title> </head><body><script type="text/javascript">
function WebDataGridView_ExitingEditMode(webDataGrid, eventArgs) { alert("exitexitmode"); ///<summary> /// If the a field in Column "Basename" is not "Standard" then set the values for columns "TextA" and "TextB" ///</summary> ///<param name="sender" type="Infragistics.Web.UI.WebDataGrid"></param> ///<param name="eventArgs" type="Infragistics.Web.UI.CancelEditModeEventArgs"></param> var answers; var grid; var cellName; var theVal; var theotherval;
var cell = eventArgs.getCell(); var othercell = cell.get_row().get_cellByColumnKey("B");
cellName = cell.get_column().get_key(); //the next code row gets the wrong value, it is the former value not the actual selected!! theVal = cell.get_value().toLowerCase(); theotherval = cell.get_row().get_cellByColumnKey("B").get_value();
othercell.get_element().style.backgroundColor = 110030;
//the actual selected value can be found in the eventArgs! //theVal = eventArgs.get_displayText() alert(cellName + theVal); alert(cellName + theotherval);
// if (cellName == "Basename") {// if (theVal != "") {// if (theVal != "standard") //if not Standard then set the default values// {// strReturn = searchWdg2(theVal); //here I do a "lookup" in another grid, you can also have these values already or do a query....// answers = strReturn.split(":"); //I get 2 values in one string separated by ":" and convert this to an array// impBCell = cell.get_row().get_cellByColumnKey("TextA");// impBCell.set_value(answers[0]); //put in the first value of the array
// impFCell = cell.get_row().get_cellByColumnKey("TextB");// impFCell.set_value(answers[1]); //put in the second value of the array// }// }// } }
function WebDataGridView_EnterEditMode(webDataGrid, evntArgs) { // alert("enteredit"); // var row = evntArgs._cell._row; // var cell = evntArgs._cell; // alert(row.get_cellCount()); // alert(cell.value);
//var selectedCell = evntArgs.getSelectedCells().getItem(0); //gets the value of the cell //var cellValue = selectedCell.get_value();
//alert(cellValue); }
function WebDataGrid1_Selection_CellSelectionChanged(sender, eventArgs) { // alert("cellchange");
// var selectedCell = eventArgs.getSelectedCells().getItem(0); //gets the value of the cell // var cellValue = selectedCell.get_value();
// alert(cellvalue); }
function changecell() {
alert("changecell"); }
</script> <form id="form1" runat="server"> <div> <asp:Label ID="Labelx" runat="server" Text="280" CssClass="label" ></asp:Label> <ig:WebDataTree ID="WebDataTree2" runat="server" DataSourceID="WebHierarchicalDataSource1" Height="241px" Width="236px" SelectionType="Single" OnSelectionChanged="WebDataTree2_OnSelectionChanged" style="margin-right: 0px" > <DataBindings> <ig:DataTreeNodeBinding DataMember="HR_DEPT_DefaultView" KeyField="DEPARTMENT_ID" TextField="DEPARTMENT_NAME" ValueField="DEPARTMENT_ID" /> </DataBindings> <AutoPostBackFlags SelectionChanged="On" /> </ig:WebDataTree> <ig:WebHierarchicalDataSource ID="WebHierarchicalDataSource1" runat="server"> <DataViews> <ig:DataView ID="HR_DEPT_DefaultView" DataMember="DefaultView" DataSourceID="HR_DEPT" /> </DataViews> </ig:WebHierarchicalDataSource> <asp:SqlDataSource ID="HR_DEPT" runat="server" ConnectionString="<%$ ConnectionStrings:hr %>" ProviderName="<%$ ConnectionStrings:hr.ProviderName %>" SelectCommand="select department_id, department_name from departments where manager_id is not null"> </asp:SqlDataSource> </div> <div> <asp:SqlDataSource ID="emp1" runat="server" CacheKeyDependency="true" ConnectionString="<%$ ConnectionStrings:hr %>" DeleteCommand="DELETE FROM "EMPLOYEES" WHERE "EMPLOYEE_ID" = :EMPLOYEE_ID" InsertCommand="INSERT INTO "EMPLOYEES" ("EMPLOYEE_ID", "FIRST_NAME", "SALARY", "DEPARTMENT_ID") VALUES (:EMPLOYEE_ID, :FIRST_NAME, :SALARY, :DEPARTMENT_ID)" ProviderName="<%$ ConnectionStrings:hr.ProviderName %>" SelectCommand="select sub.department_id,sub.DEPARTMENT_NAME,(select first_name from employees where employee_id = sub.manager_id) first_name,(select salary from employees where employee_id = sub.manager_id) salary,manager_id employee_id from ( select department_name,department_id, manager_id from departments where department_id= :DEPTID )sub"
UpdateCommand="SALARY_UPDATE" UpdateCommandType="StoredProcedure" onselecting="emp1_Selecting" > <%-- UpdateCommand="UPDATE "EMPLOYEES" SET "FIRST_NAME" = :FIRST_NAME , "SALARY" = :SALARY WHERE "EMPLOYEE_ID" = :EMPLOYEE_ID" >--%> <DeleteParameters> <asp:Parameter Name="EMPLOYEE_ID" Type="Decimal" /> </DeleteParameters> <SelectParameters> <asp:controlparameter name="DEPTID" controlid="Labelx" propertyname="Text" DefaultValue="280"/> </SelectParameters> <InsertParameters> <asp:Parameter Name="EMPLOYEE_ID" Type="Decimal" /> <asp:Parameter Name="FIRST_NAME" Type="String" /> <asp:Parameter Name="SALARY" Type="Decimal" /> <asp:Parameter Name="DEPARTMENT_ID" Type="Decimal" /> </InsertParameters> <UpdateParameters> <asp:Parameter Name="EMPLOYEE_ID" Type="Decimal" /> <asp:Parameter Name="FIRST_NAME" Type="String" /> <asp:Parameter Name="SALARY" Type="Decimal" /> </UpdateParameters> </asp:SqlDataSource> </div> <asp:ScriptManager ID="ScriptManager2" runat="server"> </asp:ScriptManager> <asp:UpdatePanel ID="pnl2" runat="server"> <ContentTemplate> <asp:Button ID="btn_save" runat="server" Text="Save" onclick="btn_save_Click" /> <asp:Label ID="Label1" runat="server" Text="Label"></asp:Label> </ContentTemplate> </asp:UpdatePanel> <ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="653px" style="margin-right: 259px" AutoGenerateColumns="false" DataKeyFields="EMPLOYEE_ID" DataSourceID="emp1"> <Columns> <ig:BoundDataField DataFieldName="DEPARTMENT_ID" Key="DEPARTMENT_ID" Width="100"> <Header Text="DEPARTMENT_ID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="DEPARTMENT_NAME" Key="DEPARTMENT_NAME" Width="100"> <Header Text="DEPARTMENT_NAME" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="EMPLOYEE_ID" Key="EMPLOYEE_ID" Width="100" Hidden="true"> <Header Text="EMPLOYEE_ID" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="FIRST_NAME" Key="FIRST_NAME" Width="100"> <Header Text="FIRST_NAME" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="SALARY" Key="SALARY" Width="100"> <Header Text="SALARY" /> </ig:BoundDataField> </Columns> <Behaviors> <ig:EditingCore AutoCRUD="true"> <Behaviors> <ig:CellEditing> </ig:CellEditing> <ig:RowAdding> </ig:RowAdding> <ig:RowDeleting /> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single"> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors> </Behaviors> </ig:WebDataGrid> <br /> <asp:SqlDataSource ID="abcDS" runat="server" ConnectionString="<%$ ConnectionStrings:hr %>" InsertCommand="ABC_INSERT" InsertCommandType="StoredProcedure" DeleteCommandType = "StoredProcedure" DeleteCommand="ABC_DELETE" ProviderName="<%$ ConnectionStrings:hr.ProviderName %>" SelectCommand="select * from abc"> <InsertParameters> <asp:Parameter Name="A" Type="String" /> <asp:Parameter Name="B" Type="String" /> <asp:Parameter Name="C" Type="String" /> </InsertParameters> <DeleteParameters> <asp:Parameter Name="A" Type="String" /> </DeleteParameters> </asp:SqlDataSource>
<ig:WebDataGrid ID="abcGRID" runat="server" AutoGenerateColumns="False" DataKeyFields="A" DataSourceID="abcDS" Height="350px" Width="400px"> <Columns> <ig:BoundDataField DataFieldName="A" Key="A"> <Header Text="A" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="B" Key="B"> <Header Text="B" /> </ig:BoundDataField> <ig:BoundDataField DataFieldName="C" Key="C"> <Header Text="C" /> </ig:BoundDataField> </Columns> <Behaviors> <ig:EditingCore> <Behaviors> <ig:RowAdding> </ig:RowAdding> <ig:RowDeleting /> <ig:CellEditing> <CellEditingClientEvents ExitedEditMode="WebDataGridView_ExitingEditMode" /> </ig:CellEditing> </Behaviors> </ig:EditingCore> <ig:Selection CellClickAction="Row" RowSelectType="Single" > <SelectionClientEvents CellSelectionChanged="WebDataGridView_ExitingEditMode" /> </ig:Selection> <ig:RowSelectors> </ig:RowSelectors> </Behaviors> </ig:WebDataGrid> </form></body></html>
Hi Zaid,
The markup you provided seems to be correct, so I would need to see your code for SelectionChanged event of the tree.
Hello Zaid,
I'm just checking if you have resolved your issue.
Hi ,
sorry for the slow response. I have not done anything on the back code as below.
Thinking maybe I should handle the posback from javascipt. can you point me to some example to handle tree selection changed postpack via javascript.
using
System;
System.Collections.Generic;
System.Linq;
System.Web;
System.Web.UI;
System.Web.UI.WebControls;
namespace
voltsweb2
{
public partial class WebForm2 : System.Web.UI.
Page
protected void Page_Load(object sender, EventArgs
e)
}
protected void WebDataTree2_OnSelectionChanged(object sender, Infragistics.Web.UI.NavigationControls.DataTreeSelectionEventArgs
Labelx.Text = e.NewSelectedNodes[0].Value;
protected void btn_save_Click(object sender, EventArgs
// emp1.Update;
protected void emp1_Selecting(object sender, SqlDataSourceSelectingEventArgs
String
select = emp1.SelectCommand;
public class DecimalBooleanConverter : Infragistics.Web.UI.GridControls.
IBooleanConverter
public object
DefaultFalseValue
get { return
0; }
DefaultTrueValue
1; }
public bool IsFalse(object
value)
if (value == null
)
return true
;
return (decimal
)value <= 1m;
public bool IsTrue(object
return false
)value > 0m;
I'm just checking if you managed to solve your issue.
Please check this thread for possible solutions of this issue - http://ko.infragistics.com/community/forums/t/65625.aspx.
Let me know if this helps.