As i add new rows, i want the default values for the new rows to be zero. The new rows are added now when i click the addNewRows button but they are just blank. How can i preassign to zero value for each of the column in the row?
First, I think you have a problem with your existing logic. It appears that you are iterating over all existing rows in your table, and at each iteration, you are creating a new row at the current index + 1. But you only add this row to the table at the very end. This means if you have 10 existing rows in your table, you're actually creating 10 new rows, but only the last iteration actually adds a row to the table, so the net affect is 1 new row. If this is not your intention, a better approach would be:
//outside the loop
drNewRow = dtCurrentTable.NewRow();
drNewRow["RowNumber"] = dtCurrentTable.Rows.Count + 1;
drNewRow["Col1"] = "0"; //assuming your drop down has a default value of 0.
drNewRow["Col2"] = "0";
Asked in February 2016Viewed 3,930 timesVoted 5Answered 2 times