User Control displayed with a loop

P

Pi

Hi guys,

I have created a web user control that has 2 datagrids on a panel. What
I need to do is to go through a collection and depending on the count
of the collection, display my control with the datagrids populated/
bound with the collections.

Although the code doesn't give me any errors, the control is not being
displayed on the webpage. I am adding the code here for both my web
control and the page that uses it. I hope someone can help me in
figuring this out.

******************************************************************************************Control
Code.
using System;
using System.Collections;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;

/// <summary>
/// Summary description for LocationAndVehicleControl.
/// </summary>
public class LocationAndVehicleControl : System.Web.UI.UserControl
{
protected System.Web.UI.WebControls.DataGrid dataGridPrintSchedule;
protected System.Web.UI.WebControls.DataGrid dataGridLocationGroup;
protected System.Web.UI.WebControls.Panel pnlHolder;

private LocationCollection locColl = new LocationCollection();
private Location _location;


#region Constructor(s)

public LocationAndVehicleControl()
{
}
#endregion

public void LocationAndVehicleControl2(Location location)
{
_location = location;

VehicleCollection vehColl;
LocationCollection locCollection = new LocationCollection();

pnlHolder = new Panel();
DataGrid dataGridLocationGroup = new DataGrid();
locCollection.Add(_location);
dataGridLocationGroup.DataSource = locCollection;
CreateLocationColumns();
dataGridLocationGroup.DataBind();

DataGrid dataGridPrintSchedule = new DataGrid();
vehColl = new VehicleCollection(_location);
dataGridPrintSchedule.DataSource = vehColl;
CreateDataColumns();
dataGridPrintSchedule.DataBind();

}

private void Page_Load(object sender, System.EventArgs
e)
{
}

#region Private Helper Methods
/// <summary>
/// Create datagrid columns dynamically
/// </summary>
private void CreateDataColumns()
{
BoundColumn bc = new BoundColumn();
bc.HeaderText = "Unit #";
bc.DataField = "UnitNumber";
bc.SortExpression = "UnitNumber";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "VIN";
bc.DataField = "VIN";
bc.SortExpression = "VIN";
bc.Visible = true;
dataGridPrintSchedul e.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Make";
bc.DataField = "Make";
bc.SortExpression = "Make";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Model";
bc.DataField = "Model";
bc.SortExpression = "Model";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Vehicle Type";
bc.DataField = "VehicleType";
bc.SortExpression = "VehicleType";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Graphics Kit";
bc.DataField = "GraphicsKit";
bc.SortExpression = "GraphicsKit";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Removal?";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Install?";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Used Kit Indicated?";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Alternate Kit Used?";
bc.Visible = true;
dataGridPrintSchedule.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "Notes";
bc.Visible = true;
bc.ItemStyle.Width = 300;
dataGridPrintSchedule.Columns.Add(bc);
}

private void CreateLocationColumns()
{
BoundColumn bc = new BoundColumn();
bc.HeaderText = "Address";
bc.DataField = "Address";
bc.SortExpression = "Address";
bc.Visible = true;
dataGridLocationGroup.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "City";
bc.DataField = "City";
bc.SortExpression = "City";
bc.Visible = true;
dataGridLocationGroup.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "State";
bc.DataField = "State";
bc.SortExpression = "State";
bc.Visible = true;
dataGridLocationGroup.Columns.Add(bc);

bc = new BoundColumn();
bc.HeaderText = "ZipCode";
bc.DataField = "Zip";
bc.SortExpression = "Zip";
bc.Visible = true;
dataGridLocationGroup.Columns.Add(bc);
}
}
}



******************************************************************Code
that calls the user control.

public class ScheduleToPrint : System.Web.UI.Page
{
private LocationAndVehicleControl locationControl = new
LocationAndVehicleControl();
}


VehicleCollection vehColl;
LocationCollection locCollection = new LocationCollection();

foreach(Location location in locColl)
{
LoadControl("~/LocationAndVehicleControl.ascx");
LocationAndVehicleControl locationControl =
(LocationAndVehicleControl)
Page.LoadControl("~/LocationAndVehicleControl.ascx");
vehColl = new VehicleCollection(location);

locationControl.LocationAndVehicleControl2(location);
locationControl.ID = "locationVehControl"+location.ID.ToString();
this.Page.Controls.Add(locationControl);
locationControl.Visible = true;
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top