I'm trying to add values from TextBoxes to a DataTable so that I can check for null values (and later, duplicate values)
I am able to add Rows to the table directly from the TextBoxes, but when I try and dynamically add the last TextBox(es) my code is adding a String rather than the required Value as below:
DataTable dt = new DataTable("CheckforNulls");
dt.Columns.Add("ColumnToCheck", typeof(string));
dt.Rows.Add(txtSettingsOneValue.Text.ToLower());
dt.Rows.Add(txtSettingsTwoValue.Text.ToLower());
//ComboBox that has a value between 1 and 12
int x = int.Parse(cbSettingsThreeValue.SelectedItem.ToString());
int i = 1;
while (i <= x)
{
string threeValue = "txtSettingsThreeValue" + i + ".Text.ToLower()";
dt.Rows.Add(threeValue);
i++;
}
At the moment my DataTable looks like below after running through
ColumnToCheck
V
S
txtSettingsThreeValue1.Text.ToLower()
Is there any way of converting the string to an Existing TextBox Name and then adding it to the Value of the TextBox to the DataTable?