Monday, September 27, 2010

Working with BDC picker Control in SharePoint Programatically

  By this you can use the customized  BDC picker entity. by developing the BDC picker control. The event Load will fetch the data and also connect to the instance which is ther ein the Respetive Shared service  related to the current webapplication.
    

       BDCEntityPickerID = new Microsoft.SharePoint.Portal.WebControls.ItemPicker();
            BDCEntityPickerID.ID = "BDCEntityPickerID";
            BDCEntityPickerID.AllowTypeIn = true;
            BDCEntityPickerID.AllowEmpty = false;
            BDCEntityPickerID.AutoPostBack = true;
            BDCEntityPickerID.MultiSelect = false;
            BDCEntityPickerID.Load += new EventHandler(BDCEntityPickerID_Load);
           Controls.Add(BDCEntityPickerID);


  protected void BDCEntityPickerID_Load(object sender, EventArgs e)
        {
            // Set extended data

            BDCEntityPickerID.ExtendedData = GetExtendedData("MyInstance", "Tablename", "ColumnName_picker");

            // Set other properties


        }


protected Portal.ItemPickerExtendedData GetExtendedData(string lobInstanceName, string entityName, string titleFieldName)
        {
            // Create a new ExtendedData object
            Portal.ItemPickerExtendedData data = new Portal.ItemPickerExtendedData();
            // Get the LOB Instance
            LobSystemInstance lob = ApplicationRegistry.GetLobSystemInstanceByName(lobInstanceName);
            data.SystemInstanceId = lob.Id;
            // Get the entity
            Entity entity = lob.GetEntities()[entityName];
            data.EntityId = entity.Id;

            // Set the primary column id (the id of the "Title" field)
            FieldCollection fields = entity.GetSpecificFinderView().Fields;
            List secondaryColumnIds = new List();

            foreach (Field field in fields)
            {
                if (string.Equals(field.Name, titleFieldName, StringComparison.OrdinalIgnoreCase))
                {
                    data.PrimaryColumnId = field.TypeDescriptor.Id;

                }
                else
                {
                    secondaryColumnIds.Add(field.TypeDescriptor.Id);
                }
            }

            data.SecondaryColumnsIds = secondaryColumnIds.ToArray();

            return data;


        }

No comments:

Post a Comment