Retrieve Multiple Entity Records and Bind to The Asp.Net DataGridView Control Dynamically Using C#

Retrieve Multiple Entity Records and Bind to The Asp.Net DataGridView Control Dynamically Using C# code 

After getting the entity collection using the Query Objects please follow the below code.

EntityCollection RetrieveContactResultCollectionUsingEnqCallerId = GetEntityCollectionDateUsingQueryExpression(“contact”, RetrieveContactColumnSet, “telephone1”, EnquirerCallerIdNumber);

if (RetrieveContactResultCollectionUsingEnqCallerId.Entities.Count >= 1)
{
DataSet ds = new DataSet();
DataTable dt = new DataTable();
dt.Columns.Add(“Salutation”);
dt.Columns.Add(“Lastname”);
dt.Columns.Add(“Telphone1”);
dt.Columns.Add(“Telphone2”);
dt.Columns.Add(“Emailaddress1”);
dt.Columns.Add(“Gender”);
dt.Columns.Add(“Address1_telephone1”);
dt.Columns.Add(“Birthdate”);

foreach (var ContactResultUsingCallerId in RetrieveContactResultCollectionUsingEnqCallerId.Entities)
{
DataRow dr = dt.NewRow();

dr[“Salutation”] = ContactResultUsingCallerId.GetAttributeValue<OptionSetValue>(“ica_salutation”).Value.ToString();
dr[“Lastname”] = ContactResultUsingCallerId.GetAttributeValue<string>(“lastname”);
dr[“Telphone1”] = ContactResultUsingCallerId.GetAttributeValue<OptionSetValue>(“Telphone1”).Value.ToString();
dr[“Telphone2”] = ContactResultUsingCallerId.GetAttributeValue<string>(“Telphone1”);
dr[“Emailaddress1”] = ContactResultUsingCallerId.GetAttributeValue<string>(“emailaddress1”);
dr[“Gender”] = ContactResultUsingCallerId.GetAttributeValue<string>(“gender”);
dr[“Address1_telephone1”] = ContactResultUsingCallerId.GetAttributeValue<string>(“address1_telephone1”);
dr[“Birthdate”] = ContactResultUsingCallerId.GetAttributeValue<DateTime>(“birthdate”).ToString();

dt.Rows.Add(dr);

}

ds.Tables.Add(dt);

// You are now ready to bind your DataSet to your GridView
ContactSearchDataGrid.DataSource = ds;
ContactSearchDataGrid.DataBind();
}

Cheers,

Advertisements

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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