Thursday, December 22, 2011

C# : Counting "rows" in an XML structutre

Working on a system that returns an XML structure as a string.

The structure looks like:

Table
Row
Info1/
Info2/
...
/Row
/Table

I needed to find out how many rows there were.

Mr. Google to the rescue and the solution is:
XmlDocument readTable = new XmlDocument();

readTable.LoadXml(stringXml);
int rowCount = readTable.SelectNodes("Table/Row").Count;
Refer XPath Examples for the syntax of more kinds of searches you can do.

Enjoy!

Friday, December 02, 2011

ASP : The Web Form equivalent of MessageBox

When you are writing a Windows application, the ubiquitous MessageBox is extremely useful for popping up a quick debug message but it’s not available for ASP.NET Web Forms.

In such cases, use:

Response.Write("<script language='javascript'>alert('Your message');</script>");


Enjoy!