Hi,
I'm using a web tree to filter my datasource by changing the selectcommand dinamically:
protected void WebDataTree2_OnSelectionChanged(object sender, Infragistics.Web.UI.NavigationControls.DataTreeSelectionEventArgs e)
{
Labelx.Text = e.NewSelectedNodes[0].Value;
emp1.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= " + Labelx.Text
+ " )sub ";
}
----------------------
then I implement update to the grid
<asp:SqlDataSource ID="emp1" runat="server"
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 %>"
UpdateCommand="SALARY_UPDATE" UpdateCommandType="StoredProcedure"
>
<%-- UpdateCommand="UPDATE "EMPLOYEES" SET "FIRST_NAME" = :FIRST_NAME , "SALARY" = :SALARY WHERE "EMPLOYEE_ID" = :EMPLOYEE_ID" >--%>
<DeleteParameters>
<asp:Parameter Name="EMPLOYEE_ID" Type="Decimal" />
</DeleteParameters>
<InsertParameters>
<asp:Parameter Name="FIRST_NAME" Type="String" />
<asp:Parameter Name="SALARY" Type="Decimal" />
<asp:Parameter Name="DEPARTMENT_ID" Type="Decimal" />
</InsertParameters>
<UpdateParameters>
</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" />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</ContentTemplate>
</asp:UpdatePanel>
<ig:WebDataGrid ID="WebDataGrid1" runat="server" Height="350px" Width="653px"
AutoGenerateColumns="False" DataSourceID="emp1"
DataKeyFields="EMPLOYEE_ID" style="margin-right: 259px">
<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 DataFieldName="EMPLOYEE_ID" Key="EMPLOYEE_ID" Width="100" Hidden="true">
<Header Text="EMPLOYEE_ID" />
<ig:BoundDataField DataFieldName="FIRST_NAME" Key="FIRST_NAME" Width="100">
<Header Text="FIRST_NAME" />
<ig:BoundDataField DataFieldName="SALARY" Key="SALARY" Width="100">
<Header Text="SALARY" />
</Columns>
<Behaviors>
<ig:EditingCore AutoCRUD="true">
<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>
<Templates>
<ig:ItemTemplate ID="WebDataGrid1Template1" runat="server"
TemplateID="empid_template">
<Template><asp:Label ID="header_text" runat="server" Text="STOIIP under Reserves" ></asp:Label></Template>
</ig:ItemTemplate>
</Templates>
</ig:WebDataGrid>
------------------------
it seem to work if I dont filter the records, please advise how can I make this to work.
Thanks in advance
Hi Zaid,
Thank you for sharing your solution.
Please feel free to contact me if you have any further questions regarding this scenario.
Manage to solve it , what i did was remove datasource from WDG
EnableAjaxViewState="true" EnableDataViewState="true"
style="margin-right: 259px" AutoGenerateColumns="false" DataKeyFields="EMPLOYEE_ID">
but I bind it later after I change the select command
string strOldSelectCommand = emp1.SelectCommand;
//WebDataGrid1.DataKeyFields = "EMPLOYEE_ID";
WebDataGrid1.DataSourceID = emp1.ID;
WebDataGrid1.DataBind();
emp1.SelectCommand = strOldSelectCommand;
thanks for your help
Thank you for your reply.
I am still unable to replicate the issue, however a possible cause and resolution has been proposed in the following discussion:
http://community.infragistics.com/forums/p/47648/283841.aspx
Please check whether the data key field of your grid is also the primary column in your datasource.
Hope this helps.
Is there any workaround for this scenario?
I need to dynamically change the datasource, the WDG seems to display it well but fail to update,
---------------------------
Message from webpage
Async request failed
[MissingRecordException]: Requested record cannot be found by key.
at Infragistics.Web.UI.GridControls.EditingCore.OnAction(String actionType, Object id, Object value, Object tag)
at Infragistics.Web.UI.GridControls.GridBehavior.Infragistics.Web.UI.GridControls.IGridBehavior.OnAction(String actionType, Object id, Object value, Object tag)
at Infragistics.Web.UI.GridControls.GridBot.LoadAdditionalClientState(Object state)
at Infragistics.Web.UI.Framework.RunBot.HandleRaisePostDataChangedEvent()
at Infragistics.Web.UI.GridControls.GridBot.HandleRaisePostDataChangedEvent()
at Infragistics.Web.UI.Framework.Data.FlatDataBoundControl.RaisePostDataChangedEvent()
at System.Web.UI.Page.RaiseChangedEvents()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
[HttpUnhandledException]: Exception of type 'System.Web.HttpUnhandledException' was thrown.
at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest()
at System.Web.UI.Page.ProcessRequestWithNoAssert(HttpContext context)
at System.Web.UI.Page.ProcessRequest(HttpContext context)
at ASP.webform3_aspx.ProcessRequest(HttpContext context) in c:\Users\zputra\AppData\Local\Temp\Temporary ASP.NET Files\root\73a3be9a\b26e7310\App_Web_webform3.aspx.cdcab7d2.k1odlzaq.0.cs:line 0
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
OK
Hi Mr. Ivanov,
It does not work,
I also tried to do this
WebDataTree2.DataBind();
emp1.DataBind();
it seem to work but only when I click on a node twice.
Thanks
Zaid