Read XML element and display the data in TextBox
I saw many people asking this query in different forums. So I though I will share how this can be achieved in simple method.
You need to pass ID to below function to display corresponding data in textboxes. This id should be unique in order to display the data in textbox.
private void PopulateXMLData(string Empid)
{
try
{
string XMLFilePath = System.Configuration.ConfigurationManager.AppSettings["XMLFileDetails"];//add an entry in web.coinfig for XML file path.
DataSet ds = new DataSet();
ds.ReadXml(XMLFilePath);
foreach (DataRow dr in ds.Tables[0].Rows)
{
if ((dr["Employeeid"].ToString()) == Empid.ToString())
{
txtName.Text = dr["Name"].ToString().Trim();
txtAddress.Text = dr["Address"].ToString().Trim();
txtPhone.Text = dr["Phone"].ToString().Trim();
//Continue for all fields....
}
}
}
catch (Exception ex)
{
lblMsg.Text = "Error while fetching the record" + ex.Message;
}