Reputation: 329
How can I bind the button
text on form dynamically?
I want to give the user a feature where he can change the button text dynamically from the database.
So, from database, I am getting value as a dataset
Now the problem is, how can I bind this text to my button control on my form.
Can you please help me with this.
Thanks in advance.
Upvotes: 0
Views: 204
Reputation: 3494
First convert your Dataset to DataTable and use the below code . I have tested this code according to your question.
DataTable _ds = _commonDAC.GetButtonName(1); // i assume you are getting dataset form here
foreach (DataRow row in _ds.Rows)
{
string ControlName = row["ControlName"].ToString();
if( ControlName == "bttnLeftMessageOnMachine")
bttnLeftMessageOnMachine.Text = row["EventText"].ToString();
if (ControlName == "bttnSpokeToPerson")
bttnSpokeToPerson.Text = row["EventText"].ToString();
if (ControlName == "bttnHomeKitchenNotReady")
bttnHomeKitchenNotReady.Text = row["EventText"].ToString();
if (ControlName == "bttnInstallerNotReady")
bttnInstallerNotReady.Text = row["EventText"].ToString();
if (ControlName == "bttnNoAnswer")
bttnNoAnswer.Text = row["EventText"].ToString();
if (ControlName == "bttnBusyPhoneLine")
bttnBusyPhoneLine.Text = row["EventText"].ToString();
if (ControlName == "bttnPhLineNotOperation")
bttnPhLineNotOperation.Text = row["EventText"].ToString();
if (ControlName == "bttnCustomerWillCallInstaller")
bttnCustomerWillCallInstaller.Text = row["EventText"].ToString();
if (ControlName == "bttnIncorrectPhNo")
bttnIncorrectPhNo.Text = row["EventText"].ToString();
if (ControlName == "bttnOrderOnHold")
bttnOrderOnHold.Text = row["EventText"].ToString();
if (ControlName == "bttnOtherNoteRequired")
bttnOtherNoteRequired.Text = row["EventText"].ToString();
}
Upvotes: 1