Here is xml data:-
xsi:noNamespaceSchemaLocation="employee.xs">
and c# code to bind data to dropdowlist:-
protected void Page_Load(object sender, EventArgs e)
{
DataSet ds = new DataSet();
ds.ReadXml(Server.MapPath("~/XMLDataFile.xml"));
ddlEmp_List.DataSource=ds;
ddlEmp_List.DataTextField = "Name";
ddlEmp_List.DataValueField = "Employee_Number";
ddlEmp_List.DataBind ();
}
from there xml data I want to show only if "Active=True" employee name. How can do?

Manas MohapatraPosted Jan 28, 2016, 5:09 AM
Abhilash J APosted Jan 28, 2016, 5:01 AM
I am modified code like this:-
protected void Page_Load(object sender, EventArgs e)
{
var doc = XDocument.Load(Server.MapPath("~/XMLDataFile.xml"));
var res = new XDocument
(new XElement("Name", "Employee_Number",
(from i in doc.Root.Elements()
where i.Element(XName.Get("Active")).Value == "True"
select i)));
var xml = res.ToString();
DataTable dt = LINQToDataTable(xml);
ddlEmp_List.DataSource = dt;
ddlEmp_List.DataBind();
}
public DataTable LINQToDataTable
{
DataTable dtReturn = new DataTable();
// column names
PropertyInfo[] oProps = null;
if (varlist == null) return dtReturn;
foreach (T rec in varlist)
{
// Use reflection to get property names, to create table, Only first time, others will follow
if (oProps == null)
{
oProps = ((Type)rec.GetType()).GetProperties();
foreach (PropertyInfo pi in oProps)
{
Type colType = pi.PropertyType;
if ((colType.IsGenericType) && (colType.GetGenericTypeDefinition()
== typeof(Nullable<>)))
{
colType = colType.GetGenericArguments()[0];
}
dtReturn.Columns.Add(new DataColumn(pi.Name, colType));
}
}
DataRow dr = dtReturn.NewRow();
foreach (PropertyInfo pi in oProps)
{
dr[pi.Name] = pi.GetValue(rec, null) == null ? DBNull.Value : pi.GetValue
(rec, null);
}
dtReturn.Rows.Add(dr);
}
return dtReturn;
}
but it return System.Data.DataRowView like that. How to show only Active=true employee name from xml file?
Shubham KumarPosted Jan 28, 2016, 3:55 AM