DataGrid problem

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;
}
 
G

Guest

i'm sorry but there is an error in the code i posted earlier (SEE
//CORRECTION). pls. use this one:

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";
pnlGrid.Visible = true; //panel that contains the DataGrid
pnlWO.Visible = true;
pnlPrintWO.Visible = false;
}

private void btnAddAnotherLaborCategory_Click(object sender,
System.EventArgs e)
{
DataTable dataTable;
DataRow dataRow;
dataTable = (DataTable)Session["DataTable"]; //CORRECTION
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; //panel that contains the DataGrid
pnlWO.Visible = true;
pnlPrintWO.Visible = false;
dgResults.Visible = true;
}


Newbie said:
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;
}
 
G

Guest

problem fixed.

Newbie said:
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;
}
 
C

Chris

Newbie said:
i'm sorry but there is an error in the code i posted earlier (SEE
//CORRECTION). pls. use this one:

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";
pnlGrid.Visible = true; //panel that contains the DataGrid
pnlWO.Visible = true;
pnlPrintWO.Visible = false;
}

private void btnAddAnotherLaborCategory_Click(object sender,
System.EventArgs e)
{
DataTable dataTable;
DataRow dataRow;
dataTable = (DataTable)Session["DataTable"]; //CORRECTION
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; //panel that contains the DataGrid
pnlWO.Visible = true;
pnlPrintWO.Visible = false;
dgResults.Visible = true;
}


:

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;
}

When you do this:
dataTable = (DataTable)Session["DataTable"];

Does it come back with the actual table? I'm having trouble seeing how
session gets the reference to the DataTable.

Chris
 

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

Top