Bind a return value to a DataGrid using form server methods

To display a data table in a Silverlight form, you must bind the return value using server methods.

Before you begin

Create a Silverlight form for web-based content.

About this task

Note: The information in this topic is not related to WPF forms unless otherwise stated.

Procedure

  1. In the navigator, click Global Displays > Forms.
  2. From the Forms list, select the resource you want to work with.
  3. Click Display Editor > Silverlight Config.
  4. Click Add.
    Your Windows browser appears.
  5. From the <install dir>\Microsoft SDKs\Silverlight\v5.0\Libraries\Client folder, select System.Windows.Controls.Data.dll, and then click Open.
  6. Optional: In the Description field, enter new information about the file, and then click Save.
  7. Click the Designer tab.
  8. Click the Server Methods tab.
  9. Click Add.
  10. In the Properties panel, in the Source field, click the ellipsis button.
    The Pick a method dialog box appears.
  11. Expand IDatabaseService, select ExecuteStatement, and then click Next.
  12. In the Statement section, click Browse next to the Use Existing radio button.
    The Universal Browser appears.
  13. Select a statement, click OK, and then click Finish.
  14. In the Connection field, click the ellipsis button.
    The Universal Browser appears.
  15. Expand Databases > Database Connection, select a connection, and then click OK.
  16. From the EventTriggers field, click the Add button.
    The Event Triggers dialog box appears.
  17. Select the event that you want to trigger the method.
  18. Click Save.
  19. Click the Project tab.
  20. Expand <YOURPROJECTNAME> > MainPage.xaml.
  21. Double-click MainPage.xaml.cs.
  22. Add the code in bold to this page in the location indicated. Edit column names and add additional columns as appropriate for your call.
    namespace YOURPROJECTNAME
    {
    	public partial class MainPage : UserControl, IFragment
    	{
    		[Import]
    		public IFeedbackService FeedbackService { get; set; }
    
    		readonly ILog _logger = LogManagerEx.GetLogger("YOURPROJECTNAME");
    		readonly Dictionary<Type, object> _interfaceHelpers = new Dictionary<Type, object>();
    
    		public MainPage()
    		{
    			ProficyComposition.SatisfyImports(this);
    			InitializeComponent();
    
    			_interfaceHelpers[typeof(IResourceParameters)] = new FragmentMetadataByAttributes(this);
    			_interfaceHelpers[typeof(IFragmentInitialization)] = new FragmentInitialization(this);
    
    			InitializeProficyData();
    
    DataGrid1.AutoGenerateColumns = false;
                DataGrid1.Columns.Add(new DataGridTextColumn() { Header = "Header1", Binding = new Binding("[YOURCOLUMNNAME]") });
                DataGrid1.Columns.Add(new DataGridTextColumn() { Header = "Header2", Binding = new Binding("[YOURCOLUMNNAME2]") });
    
    		}
    
    		public T GetInterface<T>() where T : class
    		{
    			if (_interfaceHelpers.ContainsKey(typeof(T)))
    			{
    				var iface = _interfaceHelpers[typeof(T)] as T;
    				Debug.Assert(iface != null, "_interfaceHelpers[" + typeof(T).Name + "] didn't have an object of the right type.");
    				return iface;
    			}
    			return this as T;
    		}
    	}
    }
  23. Click Save.
  24. Click the MainForm.xaml tab.
  25. Click the Toolbox tab.
  26. Expand Custom Controls, and then select DataGrid.
    • For a WPF form, expand Grids and Panels.
  27. Drag the DataGrid control onto MainPage.xaml.
  28. From the Properties panel, go to the ItemsSource property, click the drop-down arrow, and then select Bind.
    The Binding dialog box appears.
  29. Select Server Methods > <YOURMETHODNAME> > ReturnValue > FirstTable > Rows.
    • For a WPF form, bind the InputTable property of the Data Grid control to the result of the server method.
  30. Click Save.