I am trying to dynamically create a GridView. One of the columns is the user who created the row.

JobDebrief jd = new JobDebrief(JobID);
DataGrid db = JobClass.Job_Piece.BuildGrid();
db.Columns.Add(CreateBoundColumn(jd.DbriefedByUser, "User"));
PlaceHolder.Controls.Add(db);
db.DataSource = jb.Pieces;
db.DataBind();

I created the GridView in the BuildGrid function which is in the job_piece class.

public static DataGrid BuildGrid()
{
      DataGrid NewDg = new DataGrid();

      NewDg.DataKeyField = "ID";
      NewDg.AutoGenerateColumns = false;
      NewDg.CssClass = "tblResults";
      NewDg.HeaderStyle.CssClass = "tblResultsHeader";
      NewDg.AlternatingItemStyle.CssClass = "ResultsStyleAlt";
      NewDg.ItemStyle.CssClass = "ResultsStyle";

      NewDg.Columns.Add(Load.CreateBoundColumn("AdvisedQty", "Qty Advised"));
      NewDg.Columns.Add(Load.CreateBoundColumn("PieceTypeString", "Piece Type"));
      NewDg.Columns.Add(Load.CreateBoundColumn("ReceivedQty", "Rcvd Qty"));          

      NewDg.Width = Unit.Percentage(100.00);

      return NewDg;
}

The 3 columns it is currently displaying all come from job_piece. Since user doesn't belong to this class I tried to create the column outside of this function.

The column displays the header but the rows are blank. The username comes from the JobDebrief class. But since I am binding the GridView to the pieces, db.DataSource = jb.Pieces; its not finding the information. Is there a way to bind this user column to JobDebrief?

Related posts

Recent Viewed