Wednesday, February 15, 2012

How to concatenate two Lists objects

Here we are filling the grid values to the List -

var listApp = new List < ApplicationLists > ();
var listFooter = new List< ApplicationLists >();


foreach (GridViewRow row in grdValues.Rows)
{
listApp.Add(new ApplicationLists { Code = ((TextBox)row.Cells[0].FindControl("txtCode")).Text, Value = ((TextBox)row.Cells[0].FindControl("txtValue")).Text });
}
if (((TextBox)grdValues.FooterRow.Cells[0].FindControl("txtCode")).Text != string.Empty)
{
listFooter.Add(new ApplicationLists { Code = ((TextBox)grdValues.FooterRow.Cells[0].FindControl("txtCode")).Text, Value = ((TextBox)grdValues.FooterRow.Cells[0].FindControl("txtValue")).Text });

}

Here is the line that can do the magic -

listApp.AddRange(listFooter);

No comments: