I have a form which contains several textboxes and comboboxes
I am able to loop through all the controls on this form and set the value (ctl.Text) to the Textboxes
but if I try to set the datasource (ctl.DataSource), I get an error during the build.
(when I type a DOT after ctl, I can see the Text property but not the Datasource one)
Here are my two functions, load_Labels works fine but I can't even build the app when I uncomment the datasource line in the load_DropDowns function
I also tried casting but it doesn't like it either.
If you can find the error in my code, I would really appreciate your feedback
Thanks,
Perry
Expand|Select|Wrap|Line Numbers
- void load_Labels()
- {
- try
- {
- int rw = -1;
- string sSQL = @"SELECT * FROM tbl_Label WHERE ynLabel_archive = false AND intLabel_phase = 1 ORDER BY intLabel_id ASC; "
- newDS = classObj.GetDataSet(sSQL);
- foreach (Control ctl in this.tabPage1.Controls)
- {
- if (ctl.Name.IndexOf("_textbox") > 0)
- {
- //this sets the Question ID
- rw = Convert.ToInt32(getQuePos(ctl.Name)) - 1;
- ctl.Text = newDS.Tables[0].Rows[rw].ItemArray[2].ToString();
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("load_Labels:" + ex.Message);
- }
- }
- void load_DropDowns()
- {
- try
- {
- int rw = -1;
- string sSQL = @"SELECT intStatus_id FROM tbl_Status;";
- newDS = classObj.GetDataSet(sSQL);
- foreach (Control ctl in this.tabPage1.Controls)
- {
- if (ctl.Name.IndexOf("_combobox") > 0)
- {
- ctl.DataSource = newDS.Tables[0];
- }
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show("load_DropDowns():" + ex.Message);
- }
- }