citizenzen
Programmer
I have a datatable that I created and I want to pass some of the values from a gridview into that datatable. I have a loop for the number of rows to add (based on copies). the loop works fine, but none of the other data is being written to the grid. I am testing now so that I can add more fields from the second gridview. what am I missing here?
Code:
protected void Addbtn_Click(object sender, EventArgs e)
{
//one of the records from the previous gridview
int chooseRec = Convert.ToInt32(nestedGrid.SelectedRow.Cells[2].Text);
try
{
DataTable myDataTable = new DataTable("MultipleRecs");
DataColumn myDataColumn;
DataRow myrow;
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.Int32");
myDataColumn.ColumnName = "Tape";
myDataColumn.ReadOnly = true;
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "Barcode";
myDataColumn.ReadOnly = true;
myDataTable.Columns.Add(myDataColumn);
myDataColumn = new DataColumn();
myDataColumn.DataType = System.Type.GetType("System.String");
myDataColumn.ColumnName = "Format";
myDataColumn.ReadOnly = true;
myDataTable.Columns.Add(myDataColumn);
myrow = myDataTable.NewRow();
myrow["Tape"]=chooseRec;
myrow["Barcode"]="Sample";
myrow["Format"]= "Format Example";
myDataTable.Rows.Add(myrow);
int copies;
copies = Convert.ToInt32(MasterGrid.SelectedRow.Cells[3].Text);
for (int i = 1; i < copies; i++)
{
myDataTable.Rows.Add(i);
}
testGrid.DataMember = "MultipleRecs";
testGrid.DataSource = myDataTable;
testGrid.DataBind();
}
catch (SqlException bigerr)
{
reqLabel.Text = "Errors loading data<br>" + bigerr;
}
}