This example below explains how to find controls and set them in the ItemTemplate of a ListView control when using XmlDataSource:
protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
{
if (ListView1.EditItem == null)
{
// Format the vertical % to 2 decimal places.
var data = (ListViewDataItem)e.Item;
var vert = XPathBinder.Eval(data.DataItem, "./Vert", "0");
var formatVert = float.Parse(vert.Replace("%", ""));
((Literal)e.Item.FindControl("Literal8")).Text = formatVert.ToString(VERT_FORMAT);
}
}
Thursday, 23 April 2009
Thursday, 16 April 2009
App_Code Class not working
I have a class in my App_Code folder and I am trying to reference it in my code behind. The name spaces are the same but I keep getting an error that is can't find the class.
The reason being I am using a web application project and not a web site project. In order for the class to be recognised I need to change the "Build Action" of the class file to "Complie" from "Content".
Build and it works now.
The reason being I am using a web application project and not a web site project. In order for the class to be recognised I need to change the "Build Action" of the class file to "Complie" from "Content".
Build and it works now.
Monday, 30 March 2009
Validate XML with XSD
In order to make sure your XML matches your XSD schema you need to link it. I have done this below using XElement (LINQ to XML) and then saved the file:
XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
var userSettings = new XElement("UserSettings",
new XAttribute(XNamespace.Xmlns + "xsi", ns.NamespaceName),
new XAttribute(ns + "noNamespaceSchemaLocation", ConfigurationManager.AppSettings.Get("ChartSchemaLocation")),
new XElement("Options",
new XElement("ChartType", ChartTypes.SelectedValue),
new XElement("DrawingStyle", DrawingStyle.SelectedValue),
new XElement("Theme", Theme.SelectedValue),
new XElement("Show3D", Show3D.Checked.ToString()),
new XElement("Weighted", Weighted.Checked.ToString()),
new XElement("Vertical", Vertical.Checked.ToString()),
new XElement("DisplayTitleAxis", ShowAxisTitles.Checked.ToString())));
userSettings.Save(UserSettingsFilePath);
XNamespace ns = "http://www.w3.org/2001/XMLSchema-instance";
var userSettings = new XElement("UserSettings",
new XAttribute(XNamespace.Xmlns + "xsi", ns.NamespaceName),
new XAttribute(ns + "noNamespaceSchemaLocation", ConfigurationManager.AppSettings.Get("ChartSchemaLocation")),
new XElement("Options",
new XElement("ChartType", ChartTypes.SelectedValue),
new XElement("DrawingStyle", DrawingStyle.SelectedValue),
new XElement("Theme", Theme.SelectedValue),
new XElement("Show3D", Show3D.Checked.ToString()),
new XElement("Weighted", Weighted.Checked.ToString()),
new XElement("Vertical", Vertical.Checked.ToString()),
new XElement("DisplayTitleAxis", ShowAxisTitles.Checked.ToString())));
userSettings.Save(UserSettingsFilePath);
Generating XSD from and XML file
If you want to generate an XML schema (*.xsd) file from an existing XML file you can use the xsd.exe tool.
Go to your Visual Studio command line and type in the following:
xsd.exe C:\file.xml /outputdir:C:\
Done!
Go to your Visual Studio command line and type in the following:
xsd.exe C:\file.xml /outputdir:C:\
Done!
Friday, 27 March 2009
Navigating XElement
The XMl looks like this:

XElement root = XElement.Load("data.xml");
var answers = root.CreateNavigator().Select("/Category/Subject/Question/Answer");
Then I loop through each answer...
while (answers.MoveNext())
{
Here I convert the underlying object to an Element to get the values:
var details = answers.Current.UnderlyingObject as XElement;
Now I can access the elements I want:
var val = details.Element("Description").Value;
}

XElement root = XElement.Load("data.xml");
var answers = root.CreateNavigator().Select("/Category/Subject/Question/Answer");
Then I loop through each answer...
while (answers.MoveNext())
{
Here I convert the underlying object to an Element to get the values:
var details = answers.Current.UnderlyingObject as XElement;
Now I can access the elements I want:
var val = details.Element("Description").Value;
}
ViewState Helper
A great tool to aid in viewing the percentage of the page that is ViewState.
ASP.NET ViewState Helper
ASP.NET ViewState Helper
Subscribe to:
Posts (Atom)