Get look-up data based on other lookup in c# from two tables.


In below example, I have two tables  ‘Mzk_ExpManufacture’ & ‘Mzk_ExpTrainingMaster’.

AS per the selection for ‘mzk_manufactuire’ field the data should change in ‘Employer’ field. Second table is the set up table have data for these two fields. Based on the relation will get lookup of ’mzk_manufacture’ in 1st table, to get the data in ‘employer’ field from 2nd table fallow as below code.

Call this method on the field which we want to see filter, I.e.  filter and in properties make the Autopost back ‘true’ and ‘showlookupbutton’ as  ‘Allways’

call this menthd at control level in C# : OnLookyp =”Employer_lookup”

public void Employer_lookup(object sender, AxLookupEventArgs e)


DataSetViewRow record = this.AxDataSource1.GetDataSourceView(“Mzk_ExpManufacture”).DataSetView.GetCurrent();

string empployer = Convert.ToString(record.GetRecord().GetField(“Mzk_Manufacture”));

AxLookup employerlookup = e.LookupControl;



using (Proxy.SysDataSetBuilder sysDataSetBuilder = Proxy.SysDataSetBuilder.constructLookupDataSet(this.AxSession.AxaptaAdapter, TableMetadata.TableNum(this.AxSession, “Mzk_ExpTrainingMaster”)))


employerlookup.LookupDataSet = new DataSet(this.AxSession, sysDataSetBuilder.toDataSet());



Proxy.Query query = employerlookup.LookupDataSet.DataSetViews[0].MasterDataSource.query();

using (Proxy.QueryBuildDataSource qbds1 = query.dataSourceNo(1))


using (Proxy.QueryBuildRange qbr = qbds1.addRange(TableDataFieldMetadata.FieldNum(this.AxSession, “Mzk_ExpTrainingMaster”, “Mzk_Manufacture”)))


qbr.value = empployer;



employerlookup.Fields.Add(AxBoundFieldFactory.Create(this.AxSession,        employerlookup.LookupDataSetViewMetadata.ViewFields[“Employer”]));

employerlookup.SelectField = “Employer”;

employerlookup.CausesValidation = false;


catch (System.Exception ex)


AxExceptionCategory exceptionCategory;

// This returns true if the exception can be handled here

if (!AxControlExceptionHandler.TryHandleException(this, ex, out exceptionCategory))


// The exception is system fatal – in this case we re-throw.







3 thoughts on “Get look-up data based on other lookup in c# from two tables.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s