I'm just trying to do a quick proof of concept - want to bind a webgrid to an XmlDataSource with an XPath filter, or to a simple list of objects, then modify data in some of the rows as each row is data bound. Instead of the .NET event OnItemDataBound, I see the event InitializeRow, but I can't seem to get it to fire. Does anyone know of a sample that goes over this (easy) scenario? I've used the .NET GridView control in the past, but this is my first experiment with the UltraWebGrid control, and I can't seem to find samples to handle some of these types of scenarios.
Thanks,
Bryan
Bryan:
Not sure why I missed this originally, but if you are binding to a Data Source Control like the XmlDataSource, then you should set the WebGrids DataSourceID property rather than using the DataSource property:
this.UltraWebGrid1.DataSourceID = "XmlDataSource1";this.UltraWebGrid1.DataBind();
This should work with your scenario. Note that try this with sample XML file I included in my sample it will appear as though the child bands are empty, but this is simply because there are no attributes on the child XML nodes that the XmlDataSource control can expose.
Devin
That works, but still doesn't explain the anomaly with the XmlDataSource object. I've used that pattern (XmlDataSource and XPath loaded from an XmlDocument object) successfully with the .NET GridView object. I just want to be able to add notes to the code that this pattern will or will not work when using the Infragistics controls.
Is using the XmlDataSource required in your scenario? Why not just bind directly to nodes from the XmlDocument:
XmlDocument doc = new XmlDocument();string appPath = System.Web.HttpContext.Current.Request.PhysicalApplicationPath;string xmlFilePath = Path.Combine(appPath, @"SmallMutualFundsList.xml");doc.Load(xmlFilePath);XmlNodeList nodes = doc.SelectNodes(@"//MutualFunds/Funds/Fund");this.UltraWebGrid1.DataSource = nodes;this.UltraWebGrid1.DataBind();
Devin:
Any additional feedback regarding binding directly to an XmlDocument object rather than an xml file? I'm hoping I'm just missing something simple.
I should have been more clear - I can get this to bind correctly if I specify the DataFile of the XmlDataSource; however, if I try to set the Data and Xpath properties of the XmlDataSource in the code behind (during Page_Load) using an XmlDocument's OuterXml object and my desired xPath, none of the data shows up in the grid. I have attached a web project illustrating the issue - check out page BindToXmlDoc.aspx. Wondering if I'm just missing some event - trying just DataBind() on the grid object to bind the data...