I'm working on a handheld device using C#.Net against SqlCe database. I have a form with multiple panels, each panel has its own group of textbox controls. When the form is built, I auto-bind each textbox control to its matching column name from a table I query from a database. Ex: txtFld1 = ResultTable.Fld1, txtFld2 = ResultTable.Fld2, etc. All this works no problem. If I query the table for a given record ID, the form refreshes no problem. If I click on a button on the form and manually change the value of the single row in the table of one or more fields, the form does not reflect these changes... Ex:
DataRow oDR = MySQLResultTable.Rows[0];
oDR["Fld1"] = "Something";
oDR["Fld2"] = "else";
oDR["Fld3"] = "changed";
The 3 fields on the form do not reflece these changed values. However, if I key into the specific fields, the values are pushed back into the respective data row of the MySQLResultTable, Row[0] object.
What am I missing.
Thanks
In its simplified format since I determine the control's name and find the corresponding column name in the table, here is what I have
public void BindControlsToDataTable(Control Page, DataTable oTbl )
{
String cObjName;
foreach (Control oCtrl in Page.Controls)
{
// if this control has other controls, bind them too...
if (oCtrl.Controls.Count > 0)
BindControlsToDataTable(oCtrl, oTbl);
// Now, try to do dynamic binding. The controls are created
// based on a 3 char prefix such as "txt", "cbo", "chk", etc
// with the remainder as the object name they represent...
// ex: txtDescription, txtFirstName, txtLastName, chkIsOk, etc..
cObjName = oCtrl.Name.Substring(3);
if (oTbl.Columns[lcName] != null)
{
oCtrl.DataBindings.Clear();
// we are binding the "TEXT" property of the control
// to the column name in the table/row
oCtrl.DataBindings.Add("Text", oTbl, cObjName,true,
DataSourceUpdateMode.OnPropertyChanged);
}
}
}
So again, if my textbox field is txtMyFld1, and a corresponding column name in the table is MyFld1, they will be paired-up automatically. I call this after the form is initialized and I've prepared/run my first query to populate a DataTable object and bind.
HTH