DataGrid Disappears Part 2

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dave Bailey

    DataGrid Disappears Part 2

    I am posting the entire code for this problem in hopes
    soneone can see what is wrong and why the page refreshes
    and the dataGrid disappears but the new page does not load.

    Thanks,

    Dave

    Code Follows:

    using System;
    using System.Collecti ons;
    using System.Componen tModel;
    using System.Data;
    using System.Drawing;
    using System.Web;
    using System.Web.Sess ionState;
    using System.Web.UI;
    using System.Web.UI.W ebControls;
    using System.Web.UI.H tmlControls;
    using System.Configur ation;
    using System.Data.Ole Db;

    namespace Type3CTracking
    {
    /// <summary>
    /// Summary description for MRDetailsForm.
    /// </summary>
    public class MRDetailsForm : System.Web.UI.P age
    {
    protected System.Web.UI.W ebControls.Labe l
    mrLabel;
    protected System.Web.UI.W ebControls.Pane l
    Panel1;
    protected
    System.Web.UI.W ebControls.Text Box mrText;
    protected DataGrid workorderGrid = new
    DataGrid();
    protected System.Web.UI.W ebControls.Labe l
    workorderLabel;
    protected
    System.Web.UI.W ebControls.Plac eHolder workorderHolder ;
    protected
    System.Data.Ole Db.OleDbDataAda pter oda;

    private void Page_Load(objec t sender,
    System.EventArg s e)
    {
    string mr = Request["MR"];
    mrText.Text = mr;

    if (!IsPostBack)
    {

    workorderHolder .Controls.Add(M akeWorkorderGri d());
    }
    }


    #region Web Form Designer generated code
    override protected void OnInit(EventArg s e)
    {
    //
    // CODEGEN: This call is required
    by the ASP.NET Web Form Designer.
    //
    InitializeCompo nent();
    base.OnInit(e);
    }

    /// <summary>
    /// Required method for Designer support -
    do not modify
    /// the contents of this method with the
    code editor.
    /// </summary>
    private void InitializeCompo nent()
    {
    this.Load += new
    System.EventHan dler(this.Page_ Load);

    }
    #endregion

    public DataView CreateWorkorder DataSource()
    {
    string workorderConnec t
    = "Provider=\"MSD AORA.1\";User ID=dave;Data
    Source=demo;Pas sword=xxxxx";
    string workorderSelect = "Select
    MR.Mrnum, Mrline.Mrlinenu m, Workorder.Wonum ,
    Workorder.Descr iption from" +
    " MR, Mrline, Workorder
    where MR.Mrnum = Mrline.Mrnum and Mrline.Wonum =
    Workorder.Wonum " +
    " and MR.Mrnum = " + "'" +
    mrText.Text + "'";

    oda = new OleDbDataAdapte r
    (workorderSelec t, workorderConnec t);
    DataSet ds = new DataSet();

    oda.Fill(ds, "workorder" );
    DataView workorder = ds.Tables
    ["workorder"].DefaultView;
    return workorder;
    }

    public DataGrid MakeWorkorderGr id()
    {
    //make the DataGrid

    workorderGrid.C ellPadding = 2;
    workorderGrid.C ellSpacing = 0;
    workorderGrid.W idth = 700;
    workorderGrid.B orderWidth = 1;
    workorderGrid.B orderColor =
    Color.Black;

    //turn off autogeneratecol umns
    feature
    workorderGrid.A utoGenerateColu mns
    = false;


    workorderGrid.F oreColor =
    Color.Blue;
    workorderGrid.F ont.Size = 10;
    workorderGrid.F ont.Name = "Arial";

    //sets the HeaderStyle

    workorderGrid.H eaderStyle.Back Color = Color.Gold;

    workorderGrid.H eaderStyle.Fore Color = Color.Blue;

    workorderGrid.H eaderStyle.Font .Name = "Arial";

    workorderGrid.H eaderStyle.Font .Size = 10;

    workorderGrid.H eaderStyle.Font .Bold = true;

    workorderGrid.H eaderStyle.Hori zontalAlign =
    HorizontalAlign .Center;

    //sets alternating style

    workorderGrid.A lternatingItemS tyle.BackColor =
    Color.Silver;

    workorderGrid.A lternatingItemS tyle.ForeColor =
    Color.Black;

    //sets the itemstyle

    workorderGrid.I temStyle.Horizo ntalAlign =
    HorizontalAlign .Center;

    //create the bound columns
    BoundColumn Wonum = new BoundColumn
    ();
    BoundColumn Mrlinenum = new
    BoundColumn();
    BoundColumn Desc = new BoundColumn
    ();


    Wonum.HeaderTex t = "Wonum";
    Wonum.DataField = "Wonum";

    Mrlinenum.Heade rText = "MR Line
    Number";
    Mrlinenum.DataF ield = "Mrlinenum" ;

    Desc.HeaderText = "Descriptio n";
    Desc.DataField = "Descriptio n";

    //add bound columns to datagrid
    workorderGrid.C olumns.AddAt(0,
    Wonum);
    workorderGrid.C olumns
    [0].ItemStyle.Widt h = 20;
    workorderGrid.C olumns.AddAt(1,
    Mrlinenum);
    workorderGrid.C olumns
    [1].ItemStyle.Widt h = 100;
    workorderGrid.C olumns.AddAt(2,
    Desc);

    //add a LinkButton column
    ButtonColumn bc = new ButtonColumn
    ();
    bc.ButtonType =
    ButtonColumnTyp e.LinkButton;
    bc.Text = "Click to View workorder
    details";
    bc.CommandName = "Details";
    workorderGrid.C olumns.Add(bc);
    workorderGrid.C olumns
    [3].HeaderText = "View Details";

    //bind the DataDrid
    workorderGrid.D ataSource =
    CreateWorkorder DataSource();
    workorderGrid.D ataBind();
    return workorderGrid;
    }
    public void Grid_ItemComman d (Object
    sender, DataGridCommand EventArgs e)
    {
    if ( e.CommandName == "Details" )
    {
    string targetPage
    = "workorderDetai lsForm.aspx?Wor korder=" + e.Item.Cells
    [0].Text;
    Response.Redire ct(
    targetPage, true );
    }
    }

    }


    }

Working...