G
Guest
I am using a Datagrid to show the contents of a DataTable. But it seems like
the Datagrid is not getting the contents of the Datatable when the button (
btnAddAnotherLaborCategory) is clicked.
private void Page_Load(object sender, System.EventArgs e)
{
DataTable dataTable;
DataColumn dataColumn;
DataRow dataRow;
dataTable = new DataTable("ratesTable");
dataColumn = new DataColumn();
dataColumn.ColumnName = "task";
dataColumn.DataType = System.Type.GetType("System.Int32");
dataColumn.AutoIncrement = true;
dataColumn.Caption = "Task";
dataColumn.ReadOnly = true;
dataColumn.Unique = true;
dataTable.Columns.Add(dataColumn);
DataColumn dataColumn2;
dataColumn2 = new DataColumn();
dataColumn2.DataType = System.Type.GetType("System.String");
dataColumn2.ColumnName = "consultantCategory";
dataColumn2.AutoIncrement = false;
dataColumn2.Caption = "Consultant Category";
dataColumn2.ReadOnly = true;
dataColumn2.Unique = true;
dataTable.Columns.Add(dataColumn2);
DataColumn dataColumn3;
dataColumn3 = new DataColumn();
dataColumn3.ColumnName = "rate";
dataColumn3.DataType = System.Type.GetType("System.Currency");
dataColumn3.AutoIncrement = false;
dataColumn3.Caption = "Rate";
dataColumn3.ReadOnly = true;
dataColumn3.Unique = false;
dataTable.Columns.Add(dataColumn3);
DataColumn dataColumn4;
dataColumn4 = new DataColumn();
dataColumn4.ColumnName = "hours";
dataColumn4.DataType = System.Type.GetType("System.Int32");
dataColumn4.AutoIncrement = false;
dataColumn4.Caption = "Hours";
dataColumn4.ReadOnly = true;
dataColumn4.Unique = false;
dataTable.Columns.Add(dataColumn4);
DataColumn dataColumn5;
dataColumn5 = new DataColumn();
dataColumn5.ColumnName = "subTotal";
dataColumn5.DataType = System.Type.GetType("System.Int32");
dataColumn5.AutoIncrement = false;
dataColumn5.Caption = "Sub-Total";
dataColumn5.ReadOnly = true;
dataColumn5.Unique = false;
dataTable.Columns.Add(dataColumn5);
dataRow = dataTable.NewRow();
dataRow["task"] = 1;
dataRow["consultantCategory"] = "BILLABLE TRAVEL EXPENSES";
dataRow["hours"] = 0;
dataRow["rate"] = 0;
dataRow["subTotal"] = 0;
dataTable.Rows.Add(dataRow);
dataRow = dataTable.NewRow();
dataRow["task"] = 2;
dataRow["consultantCategory"] = "UNBILLABLE TRAVEL EXPENSES";
dataRow["hours"] = 0;
dataRow["rate"] = 0;
dataRow["subTotal"] = 0;
dataTable.Rows.Add(dataRow);
dataRow = dataTable.NewRow();
dataRow["task"] = 3;
dataRow["consultantCategory"] = "BILLABLE FREIGHT";
dataRow["hours"] = 0;
dataRow["rate"] = 0;
dataRow["subTotal"] = 0;
dataTable.Rows.Add(dataRow);
Session["DataTable"] = "ratesTable";
}
private void btnAddAnotherLaborCategory_Click(object sender,
System.EventArgs e)
{
DataTable dataTable;
DataRow dataRow;
dataTable = (DataTable)Session["ratesTable"];
dataRow = dataTable.NewRow();
dataRow["task"] = dataTable.Rows.Count + 1;
dataRow["consultantCategory"] = ddlConsultantCategory.SelectedValue;
dataRow["hours"] = txtHours.Text.Trim();
dataRow["rate"] = txtRate.Text.Trim();
dataRow["subTotal"] = txtSubtotal.Text.Trim();
dataTable.Rows.Add(dataRow);
dgResults.DataSource = dataTable;
pnlGrid.Visible = true;
pnlWO.Visible = true;
pnlPrintWO.Visible = false;
dgResults.Visible = true;
}
the Datagrid is not getting the contents of the Datatable when the button (
btnAddAnotherLaborCategory) is clicked.
private void Page_Load(object sender, System.EventArgs e)
{
DataTable dataTable;
DataColumn dataColumn;
DataRow dataRow;
dataTable = new DataTable("ratesTable");
dataColumn = new DataColumn();
dataColumn.ColumnName = "task";
dataColumn.DataType = System.Type.GetType("System.Int32");
dataColumn.AutoIncrement = true;
dataColumn.Caption = "Task";
dataColumn.ReadOnly = true;
dataColumn.Unique = true;
dataTable.Columns.Add(dataColumn);
DataColumn dataColumn2;
dataColumn2 = new DataColumn();
dataColumn2.DataType = System.Type.GetType("System.String");
dataColumn2.ColumnName = "consultantCategory";
dataColumn2.AutoIncrement = false;
dataColumn2.Caption = "Consultant Category";
dataColumn2.ReadOnly = true;
dataColumn2.Unique = true;
dataTable.Columns.Add(dataColumn2);
DataColumn dataColumn3;
dataColumn3 = new DataColumn();
dataColumn3.ColumnName = "rate";
dataColumn3.DataType = System.Type.GetType("System.Currency");
dataColumn3.AutoIncrement = false;
dataColumn3.Caption = "Rate";
dataColumn3.ReadOnly = true;
dataColumn3.Unique = false;
dataTable.Columns.Add(dataColumn3);
DataColumn dataColumn4;
dataColumn4 = new DataColumn();
dataColumn4.ColumnName = "hours";
dataColumn4.DataType = System.Type.GetType("System.Int32");
dataColumn4.AutoIncrement = false;
dataColumn4.Caption = "Hours";
dataColumn4.ReadOnly = true;
dataColumn4.Unique = false;
dataTable.Columns.Add(dataColumn4);
DataColumn dataColumn5;
dataColumn5 = new DataColumn();
dataColumn5.ColumnName = "subTotal";
dataColumn5.DataType = System.Type.GetType("System.Int32");
dataColumn5.AutoIncrement = false;
dataColumn5.Caption = "Sub-Total";
dataColumn5.ReadOnly = true;
dataColumn5.Unique = false;
dataTable.Columns.Add(dataColumn5);
dataRow = dataTable.NewRow();
dataRow["task"] = 1;
dataRow["consultantCategory"] = "BILLABLE TRAVEL EXPENSES";
dataRow["hours"] = 0;
dataRow["rate"] = 0;
dataRow["subTotal"] = 0;
dataTable.Rows.Add(dataRow);
dataRow = dataTable.NewRow();
dataRow["task"] = 2;
dataRow["consultantCategory"] = "UNBILLABLE TRAVEL EXPENSES";
dataRow["hours"] = 0;
dataRow["rate"] = 0;
dataRow["subTotal"] = 0;
dataTable.Rows.Add(dataRow);
dataRow = dataTable.NewRow();
dataRow["task"] = 3;
dataRow["consultantCategory"] = "BILLABLE FREIGHT";
dataRow["hours"] = 0;
dataRow["rate"] = 0;
dataRow["subTotal"] = 0;
dataTable.Rows.Add(dataRow);
Session["DataTable"] = "ratesTable";
}
private void btnAddAnotherLaborCategory_Click(object sender,
System.EventArgs e)
{
DataTable dataTable;
DataRow dataRow;
dataTable = (DataTable)Session["ratesTable"];
dataRow = dataTable.NewRow();
dataRow["task"] = dataTable.Rows.Count + 1;
dataRow["consultantCategory"] = ddlConsultantCategory.SelectedValue;
dataRow["hours"] = txtHours.Text.Trim();
dataRow["rate"] = txtRate.Text.Trim();
dataRow["subTotal"] = txtSubtotal.Text.Trim();
dataTable.Rows.Add(dataRow);
dgResults.DataSource = dataTable;
pnlGrid.Visible = true;
pnlWO.Visible = true;
pnlPrintWO.Visible = false;
dgResults.Visible = true;
}