Click here to Skip to main content
14,240,732 members
Rate this:
Please Sign up or sign in to vote.
See more:
Hello Guys,
I am building an application in which i have to store the data of transporter and the quotation they give when we bargain with them. I have two lists of object type.

List <Quotations> lstQuotations = quotationBL.getQuotations(quotation);
List <Transporter> transporterDetails = transBL.getTransporterList(lstQuotations);

getQuotations and getTransporterList are the functions that returns these lists.
quotationBL and transBL are the objects that take the execution to business logic class.

Now Coming to the point, i want to Merge the above mentioned two lists (lstQuotations and transporterDetails ) into a single structure (like DataTable or another List<someothertype>, etc).
Guys tell me how to solve this problem programmatically, after solving this problem i will Bind the new structure to my Repeater Control via DataBind().
Sorry about my English or if that question sounds ugly.
Updated 23-Feb-12 6:19am
Oshtri Deka 23-Feb-12 15:11pm
Do Quotations and Transporter classes inherit same super class or interface?

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

I'm not aware of a more elegant solution than either:

  • Create a data table with two columns (I assume you know how to do this); or
  • Make a data class that contains the two items and make a list of those.
    class QuotationTransporter {
     public Quotation Quotation { get; set; }
     public Transporter Transporter { get; set; }
     public QuotationTransporter(Quotation q, Transporter t){
      Quotation = q; Transporter = t;
    List<QuotationTransporter> Merge(List<Quotation> q, <Transporter> t){
     if(q.Count != t.Count) throw new ArgumentException("Lists must be same length");
     List<QuotationTransporter> r = new List<QuotationTransporter>(q.Count);
     for(int i = 0; i < q.Count; i++)
      r.Add(new QuotationTransporter(q[i], t[i]);
     return r;

It feels like it should be possible with a LINQ join query, though. Perhaps one of the LINQ gurus will come around and demonstrate that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100