private DataTable CreateDataTable()
{//---Create datatable with datatype
DataTable myDataTable = new DataTable();
DataColumn myDataColumn;
///id//Specification/SpId/SelectBK/QtyGWt/Unit//TotalLess/Netwt
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.Int32");
myDataColumn.ColumnName = "id";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "Specification";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "SpId";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "SelectBK";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.Double");
myDataColumn.ColumnName = "QtyGWt";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "Unit";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.Double");
myDataColumn.ColumnName = "TotalLess";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.Double");
myDataColumn.ColumnName = "Netwt";
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = Type.GetType("System.String");
myDataColumn.ColumnName = "NUnit";
myDataTable.Columns.Add(myDataColumn);
return myDataTable;
}
then use this data table call this on load form
datatable GridTable=new Datatable();
Gridtable=CreateDataTable();
Then You want to fill the value in table then use
AddDataToTable(this.ddlSpecification.Text.ToString(), this.ddlSpecification.SelectedValue.ToString(), this.ddlSelectBK.Text.ToString(), this.txtQTYgrosswt.Text.Trim(), this.ddlUnit.Text.Trim(), this.txtLessWt1.Text.Trim(), this.txtLessWt2.Text.Trim(), this.txtLessWt3.Text.Trim(), this.txtLessWt4.Text.Trim(), this.txtLessWt5.Text.Trim(), this.txtTotalLessWt.Text.Trim(), this.txtNetWt.Text.Trim(), this.ddlNUnit.Text.Trim(), GridTable);
above function pass the value in table after that use blow funation
private void AddDataToTable(string Specification, string SpId, string SelectBK, string QtyGWt, string Unit, string lesswt1, string lesswt2, string lesswt3, string lesswt4, string lesswt5, string TotalLess, string Netwt, string NUnit, DataTable myTable)
{
try
{
DataRow row;
row = myTable.NewRow();
//row["id"] = Guid.NewGuid().ToString();
row["id"] = myTable.Rows.Count + 1;
row["Specification"] = Specification;
row["SpId"] = Convert.ToInt32(SpId);
row["SelectBK"] = SelectBK;
row["QtyGWt"] = QtyGWt;
row["Unit"] = Unit;
row["Lesswt1"] = lesswt1; row["Lesswt2"] = lesswt2; row["Lesswt3"] = lesswt3; row["Lesswt4"] = lesswt4; row["Lesswt5"] = lesswt5;
row["TotalLess"] = TotalLess;
row["Netwt"] = Netwt;
row["NUnit"] = NUnit;
myTable.Rows.Add(row);
}
catch (Exception)
{
// throw;
}
}
Thanks u for use this code any problem mail me
mhshry@gmail.com