User Control displayed with a loop

Discussion in 'ASP .Net Web Controls' started by Pi, Mar 30, 2006.

  1. Pi

    Pi Guest

    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;
    }
     
    Pi, Mar 30, 2006
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Tom Rowton
    Replies:
    2
    Views:
    683
    Tom Rowton
    Aug 1, 2003
  2. Mad Scientist Jr
    Replies:
    0
    Views:
    668
    Mad Scientist Jr
    Mar 22, 2006
  3. boney
    Replies:
    1
    Views:
    591
  4. Jonathan Wood

    User Control to Control Other User Control

    Jonathan Wood, Jan 24, 2010, in forum: ASP .Net
    Replies:
    4
    Views:
    573
    Jonathan Wood
    Feb 2, 2010
  5. Isaac Won
    Replies:
    9
    Views:
    419
    Ulrich Eckhardt
    Mar 4, 2013
Loading...

Share This Page