Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application

In this article, I will tell you how to Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application.

Pass a Parameter into a Screen from the Command Bar in a LightSwitch Application step by step.

Step 1: Right click on the  OrderHeader table->Add Query.


Step 2: Change query name (OpenOrders)->Add filter (ShippedDate is null)->Save like the below image.

image2.gif

Step 3: Add screen->List and Details screen->Select OpenOrder from screen data->Check OrderHeader->Ok.

image3.gif

Step 4: Now edit query of  OpenOrders->Add filter->Select CustomerID as parameter->Add new ID->Parameter (CustomerID) and type is Integer->Save.

image4.gif

Step 5: Click OpenOrderListDetail screen->AddDataItem->Local Property->Type (Integer)->Name (CustomerID)->Ok->Check parameter box.

image5.gif

Step 6: Click CustomerID of OpenOrder->Select Parameter Binding as CustomerID.

image6.gif

Step 7: Click CustomerDetail screen->Screen CommandBar->Add->New button->Write name (OpenOrder)->Ok.

image7.gif

Step 8: Now Choose image->Import image->Ok.

image8.gif

Step 9: Right click on OpenOrder->Edit Execute Code->Write the below code.

image9.gif

  1. using System;  
  2. using System.Linq;  
  3. using System.IO;  
  4. using System.IO.IsolatedStorage;  
  5. using System.Collections.Generic;  
  6. using Microsoft.LightSwitch;  
  7. using Microsoft.LightSwitch.Framework.Client;  
  8. using Microsoft.LightSwitch.Presentation;  
  9. using Microsoft.LightSwitch.Presentation.Extensions;  
  10. namespace LightSwitchApplication  
  11. {  
  12.     public partial class CustomerDetail  
  13.     {  
  14.         partial void Customer_Loaded(bool succeeded)  
  15.         {  
  16.             // Write your code here.  
  17.             this.SetDisplayNameFromEntity(this.Customer);  
  18.         }  
  19.         partial void Customer_Changed()  
  20.         {  
  21.             // Write your code here.  
  22.             this.SetDisplayNameFromEntity(this.Customer);  
  23.         }  
  24.         partial void CustomerDetail_Saved()  
  25.         {  
  26.             // Write your code here.  
  27.             this.SetDisplayNameFromEntity(this.Customer);  
  28.         }  
  29.         partial void OenOrders_Execute()  
  30.         {  
  31.             // Write your code here.  
  32.             this.Application.ShowOpenOrdersListDetail(this.Customer.Id)  
  33.         }  
  34.     }  
  35. }
Step 10: Run application->Open any customer->Click OpenOrder image->Design Screen->Customer property->Check show as a link->Save.

Step 11: Click OpenOrderListDetail screen->AddDataItem->Query->Select Customer_SinglrOrDefault->Ok.

image10.gif

Step 12 Click Id of Customer->Select Parameter Binding (CustomerID).

image11.gif

Step 13: Run application->Design screen->Add->AddNew>Move up first->Save.

image13.gif

Step 14: Click + sign in OpenOrder->Fill data->Save.

image14.gif