.Net, ASP.NET, HTML, JavaScript, ListView, WebForms, XML, XML Control, XPath, XSLT

Call a JavaScript Function in an XSL StyleSheet of an ASP.NET XML Control

Using an XSL stylesheet together with an ASP.NET XML control can be a great way to format the output of a database query. For instance a cool implementation is that you can embed an XML control within a ListView control so that you can output a tree-like structure in your ListView rather than the standard tabular structure.

One surprisingly tricky thing is setting up a call to a JavaScript function within your XSL stylesheet that passes data from your database query dynamically. Unlike traditional ASP/ASP.NET you cannot directly output your database variable in your XSL markup (ie: along the lines of: Text='<%# Eval(“SomeData”) %>’). Instead, you first need to assign the dynamic data to a variable and then you need to use that variable to format your JavaScript call.

Continue reading “Call a JavaScript Function in an XSL StyleSheet of an ASP.NET XML Control”

Advertisements
.Net, ASP.NET, ListView, Programming, VB.NET, Web Development

Custom Function to Inject HTML Tags Iteratively into ListView Column Text

The ASP.NET system libraries offer powerful string manipulation functionality in the form of extensive Regular Expression support as well as String-specific functions such as Split and Replace. In 99% of cases these functions are sufficient to use to quickly manipulate strings. However in one case I had to put together a special function of my own.

What was the problem & why build a custom function?

The UI to be developed was rather simple. I wanted to write a basic search Web page that contained a TextBox for the user to enter their search text, a Submit button to run the search, and a ListView control to display the search results.

Although from the UI perspective everything was very straightforward, the catch became clear with the requirement to have the search term bolded in the search results shown by the ListView control. This became a problem for the following reasons: Continue reading “Custom Function to Inject HTML Tags Iteratively into ListView Column Text”