I want to set XML value into ContentPage Control from masterPage.
Textbox/ddl/checkbox etc.
<form><Childs><HiddenField><ID>hdnSessionUserpracticeId</ID><Value>7c180b88-57d6-4c38-b47b-d95388742bf4</Value></HiddenField><Label><ID>lblOnlineUser</ID><Text> <b>Live Users: </b>1</Text></Label><DropDownList><ID>cbo_Practice</ID><SelectedValue>7c180b88-57d6-4c38-b47b-d95388742bf4</SelectedValue></DropDownList></Childs></form>
public void BindValuesAfterLogin(Guid UserPracticeId, System.Web.UI.ControlCollection controls)
{
DataSet ds = new DataSet();
using (var en = new DentalComplianceEntities())
{
var logoutData = en.LogoutTables.Where(q => q.UserPracticeId == UserPracticeId).FirstOrDefault();
if (logoutData != null)
{
FinalXML = logoutData.FormData;
XDocument doc = XDocument.Parse(FinalXML);
XmlReader reader = doc.CreateReader();
ds.ReadXml(reader);
BindFormControls(ds, controls);
//DataSet dataTable = XMLtoDataTable(logoutData.FormData);
//en.LogoutTables.Remove(logoutData);
//en.SaveChanges();
}
}
}
private void BindFormControls(DataSet ds, System.Web.UI.ControlCollection controls)
{
foreach (DataTable dt in ds.Tables)
{
var name = dt.TableName;
for (int i = 0; i < dt.Rows.Count; i++)
{
foreach (Control c in controls)
{
switch (name)
{
case "HiddenField":
if (c is HiddenField && ((HiddenField)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((HiddenField)c).Value = Convert.ToString(dt.Rows[i]["Value"]);
}
break;
case "TextBox":
var ass = c.Page.FindControl(dt.Rows[i]["ID"].ToString());
if (c is TextBox && ((TextBox)c).Page.ID == Convert.ToString(dt.Rows[i]["ID"]))
//if (ass.Controls. == Convert.ToString(dt.Rows[i]["ID"]))
{
((TextBox)c).Text = Convert.ToString(dt.Rows[i]["Text"]);
}
break;
case "Label":
if (c is Label && ((Label)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((Label)c).Text = Convert.ToString(dt.Rows[i]["Text"]);
}
break;
case "CheckBox":
if (c is CheckBox && ((CheckBox)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((CheckBox)c).Checked = Convert.ToBoolean(dt.Rows[i]["Checked"]);
}
break;
case "CheckBoxList":
if (c is CheckBoxList && ((CheckBoxList)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((CheckBoxList)c).SelectedValue = Convert.ToString(dt.Rows[i]["SelectedValue"]);
}
break;
case "RadDateInput":
if (c is RadDateInput && ((RadDateInput)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((RadDateInput)c).SelectedDate = string.IsNullOrEmpty(Convert.ToString(dt.Rows[i]["SelectedDate"])) ? ((RadDateInput)c).SelectedDate : Convert.ToDateTime(dt.Rows[i]["SelectedDate"]);
}
break;
case "RadEditor":
if (c is RadEditor && ((RadEditor)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((RadEditor)c).Content = Convert.ToString(dt.Rows[i]["Content"]);
}
break;
case "RadScheduler":
if (c is RadScheduler && ((RadScheduler)c).ID == Convert.ToString(dt.Rows[i]["ID"]))
{
((RadScheduler)c).SelectedDate = string.IsNullOrEmpty(Convert.ToString(dt.Rows[i]["SelectedDate"])) ? ((RadScheduler)c).SelectedDate : Convert.ToDateTime(dt.Rows[i]["SelectedDate"]);
}
break;
}
}
}
}
}