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:
This should be pretty easy to do as you state. I created a couple of samples (attached) using the 2007 Volume 3 WebGrid that demonstrate the use of the event both binding to a SqlDataSource and also an XmlDataSource. Note to try the SQL sample you will have to update the connection string in the web.config. Its currently pointing to a Northwind database.
There should not be any magic, just connect the data source control and wire the InitializeRow event. If you create it via the property grid, you should see something like this get added to the WebGrid markup:
OnInitializeRow="UltraWebGrid1_InitializeRow"
You can of course add that manually yourself or even wire the event up in code:
this.UltraWebGrid1.InitializeRow+=new Infragistics.WebUI.UltraWebGrid.InitializeRowEventHandler(UltraWebGrid1_InitializeRow);
Hope that helps.
Devin
Devin:
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...
Any additional feedback regarding binding directly to an XmlDocument object rather than an xml file? I'm hoping I'm just missing something simple.
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.
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();