Monthly Archives: March 2011

WebHierarchicalDataGrid: Locate cell by column name

If you need to get/set value of a specific cell in WHDG Row (which is of GridRecord or ContainerGridRecord type) the only way to do it is by Cell index e.g.

Protected Sub xMyGrid_InitializeRow(ByVal sender As Object, ByVal e As GridControls.RowEventArgs) Handles xMyGrid.InitializeRow
   e.Row.Items(15).Value = 42
End Sub

But what if you don’t know cell/column index and only column name is known? Then the trick is to find the index first. Consider following code:

Protected Sub xMyGrid_InitializeRow(ByVal sender As Object, ByVal e As GridControls.RowEventArgs) Handles xMyGrid.InitializeRow

   Dim oParent as GridControls.ContainerGrid = e.Row.Items.Grid
   Dim iColIndex as Integer

   if oParent.Columns("MY_COLUMN_NAME") IsNot Nothing
      iColIndex = oParent.Columns("MY_COLUMN_NAME").Index
      e.Row.Items(iColIndex).Value = 42
   End If

End Sub

It’s pretty straightforward, first you locate grid to which the row belongs, then locate column in that grid by name and get index of that column and finally locate cell in the row by that index. This method will work at any depth in the WHDG hierarchy.

Posting from HELLOTXT to Custom URL

HELLOTXT is an excellent service allowing you to update multiple social networks, blogs and microblogs at once. Among supported services – WordPress, Blogger, Delicious, Facebook, Twitter and many more.

One of the selections is Custom URL. What it does – it allows you to specify URL of your own site and then you’re free to do whatever you need with received data. This makes HELLOTXT services very expendable. For example natively it doesn’t support Russian LiveInternet network, but using Custom URL my site can accept posted data and then create a new LiveInternet entry via posting by email.

Setting Custom URL is very easy in HELLOTXT. You specify 2 fields:1st is Name*Code which can hold any data that your site can check to verify that call is authentic, 2nd field is URL – the URL of your site. Important! Make sure you specify actual file name, e.g. if it’s http://www.mysite.com/hellotxt/index.php – enter it as is, if your enter just http://www.mysite.com/hellotxt you may get 405 error “service not allowed”.

Once this part is setup your page will receive following FORM fields in HTTP request:

name, body, title, msg_code, image_code, video_code, audio_code, v

field “name” will have name*security code you specified in Custom URL setup. The rest depends on your setup, in my case (microblogging/status) field “body” had the actual message.

Making HoverCssClass work in WebDataTree

Infragistics WebDataTree control offers extensive support of CSS for tree styling. One of the options HoverCssClass is intended to alter tree node appearance when mouse pointer hovers over it:

HoverCssClass properting in Infragistics WebDataTree

Unfortunately it doesn’t seem to have any effect on the tree appearance. When I set that class to simple underline node:

.fnTreeHover {text-decoration:underline}

nothing happened. I found the workaround when I noticed that the tree is rendered as an ancor tag <A> inside of <LI> tag:

WebDataGrid rendered in HTML

The solution is to apply style to this combination:

LI A:hover {text-decoration:underline}

Bingo. Now tree nodes are underlying when mouse is over them.

Individual Sorting of SELECT queries in the UNION

UNION is a very common operator used in SQL, it allows to combine result of multiple queries into one. Unfortunately if you want to sort this unified resultset sorting is applied to entire result at once. But what if you wan to sort queries-participants individually?

Let’s say you have 2 following queries from Northwind database:

SELECT TOP (5) CompanyName FROM Suppliers ORDER BY CompanyName
Aux joyeux ecclésiastiques
Bigfoot Breweries
Cooperativa de Quesos 'Las Cabras'
Escargots Nouveaux
Exotic Liquids

and

SELECT TOP (5) ProductName FROM Products ORDER BY ProductName
Alice Mutton
Aniseed Syrup
Boston Crab Meat
Camembert Pierrot
Carnarvon Tigers

And now you want to combine them into a single result, adding title lines to separate each result. The direct approach would be:

SELECT 'Suppliers' AS Name
UNION
SELECT TOP (5) CompanyName FROM Suppliers
UNION
SELECT 'Products'
UNION
SELECT TOP (5) ProductName FROM Products
ORDER BY Name

But result is far from what we wanted

Alice Mutton
Aniseed Syrup
Aux joyeux ecclésiastiques
Bigfoot Breweries
Boston Crab Meat
Camembert Pierrot
Carnarvon Tigers
Cooperativa de Quesos 'Las Cabras'
Escargots Nouveaux
Exotic Liquids
Products
Suppliers

Entire resultset is sorted uniformally and products are mixed with suppliers.
Continue reading →

UltraWebGrid: Hiding ServerOnly columns during export to Excel

If you’re using Infragistics UltraWebGrid with ExcelExporter and your grid has columns marked as “ServerOnly” – they’re visible in exported Excel worksheet even though the grid doesn’t show them onscreen. To hide these column in exported file, mark them as “Hidden” as well. This will have no additional effect on the way grid looks on screen, but the columns will be gone from the worksheet.

Fix for first release of Unique Article Wizard multisite WordPress plugin

If you’re using UAW plugin in your WordPress MU/3.0+ blog, starting version 3.1.26 it supports multisite environment (ability to have individual settings for subdomain blogs). But initial release had a bug resulting in errors of missing config.php as well as

permission denied – your token does not match our records

To fix this error, open file article_mods.php and locate function uaw_add_article. In global declaration after $win add , $blog_id. Then locate line

$uaw_config_file = getcwd() . ($win == "" ? '/config.php' : '\\config.php');

and replace it with

if ($blog_id == '1') 
   {$uaw_config_file = getcwd() . ($win == "" ? '/config.php' : '\\config.php');}
else
   {$uaw_config_file = getcwd() . ($win == "" ? '/config_'.$blog_id.'.php' : '\\config_'.$blog_id.'.php');}

Upload modified file to you UAW plugin directory, overwriting the old one and you’re good to go

Run JavaScript from both full and partial ASP.NET postback

A while back I posted a function that would run JavaScript from both full page postback and Infragistics async postback. But what if you’re using “normal” Microsoft AJAX where partial postbacks are controlled by ScriptManager and you need to run JavaScript on initial page load, full postback and from inside of Update Panel? And even in Infragistics the newer Aikido controls use ScriptManager for async communications.

Here is an overridden version of that RunJavaScript function for pages with ScriptManager:

Public Shared Sub RunJavascript(ByVal _
   i_oScriptManager As Web.UI.ScriptManager,  ByVal i_sJScode As String)

   If i_oScriptManager.IsInAsyncPostBack Then
      i_oScriptManager.RegisterStartupScript(i_oScriptManager.Page, _
      i_oScriptManager.Page.GetType, "JSCode" & Rnd(1).ToString, _
      i_sJScode, True)
   Else
      i_oScriptManager.Page.ClientScript.RegisterStartupScript( _
      i_oScriptManager.Page.GetType, "JSCode" & Rnd(1).ToString,
      i_sJScode, True)
   End If
End Sub

It accepts 2 parameters – ScriptManager control from the page and string with JavaScript code. Function checks if it’s an async postback and if so – calls ScriptManager’s RegisterStartupScript method, otherwise page’s RegisterStartupScript is used. Here’s an example of usage:

RunJavascript(Me.ScriptManager1, "alert('Hello world from any postback!');")

UltraWebGrid: Set filter icon when manually handling RowFilterApplying event

If you’re using Infragistics UltraWebGrid and manually handling grid’s RowFilterApplying event by doing your own filtering/querying and then canceling the event by setting parameter e.Cancel = True, one of the side-effects is that column filter icon never changes to “applied” image.

To work around this limitation you need to change the image yourself. This involves 2 steps:

1st step – In the server side, code in RowFilterApplying event handler loops thru filtered columns, getting column index, filtered state and calling a JavaScript function that would actually set the image:

Protected Sub xmyGrid_RowFilterApplying(ByVal sender As Object, ByVal e As UltraWebGrid.FilterEventArgs) Handles xmyGrid.RowFilterApplying

    ' ... Your own filtering/querying code

    Dim xGrid As UltraWebGrid = sender

    For Each oFilter As ColumnFilter In xGrid.Rows.ColumnFilters
         If oFilter.FilterConditions.Count = 0 OrElse oFilter.FilterConditions(0).ComparisonOperator = FilterComparisionOperator.All Then
            RunJavascript(Me, "setFilterIcon(" & oFilter.Column.Index & ", 'MyImages/ig_tblFilter.gif');")
         Else
            RunJavascript(Me, "setFilterIcon(" & oFilter.Column.Index & ", 'MyImages/ig_tblFilterApplied.gif');")
         End If
    Next

    e.Cancel = True

End Sub

During the loop code double checks if filter is applied to current column and if so passes URL of “applied” filter image to the JavaScript function – in this case “MyImages/ig_tblFilterApplied.gif”. Otherwise URL of “empty” filter is passed – in this case “MyImages/ig_tblFilter.gif”. To generate JavaScript call from ASP.NET code I am using RunJavascript function which works correctly both on normal postback and Infragistics partial postback (read WARP panel).

2nd step – And here’s JavaScript function that sets the image:

// Set's filter icon of the specifiec column
function setFilterIcon(i_iColumnIndex, i_sFilterImageURL) {
    var sThId = igtbl_getGridById('xmyGrid').Bands[0].Columns[i_iColumnIndex].Element.id; 
    document.getElementById(sThId).firstChild.lastChild.src = i_sFilterImageURL
}

Using passed in column index, code locates column object and its DOM “TH” element (note: You have to get an ID of the element first, and then locate element by calling document.getElementById, using Column.Element for some reason returns an empty TH tag). Once element is located, code locates filter image inside and sets its source to passed image URL

WebHierarchicalDataGrid: Helpful client functions for row selection

Working with row selection in Infragistics WebHierarchicalDataGrid can be complicated since it maintains independent row selection collection for each row island and basic operations (select/unselect) aren’t that obvious. I put together a few functions to make it a little bit easier.

This first function is very basic, it returns total count of selected rows across all expanded row islands, no matter what depth. The key here is get_selectedRowsResolved() method of Selection behavior which returns an array of all selected rows:

// Returns number of selected rows from all rowislands in WebHiearchicalDataGrid
// i_oGrid: Infragistics WebHiearchicalDataGrid object
function selRowsCount(i_oGrid) {
    return  i_oGrid.get_gridView().get_behaviors().get_selection().get_selectedRowsResolved().length 
}

The following function loops thru all selected rows, collecting values from specific column (useful for example for collecting IDs of selected rows). It accepts 3 parameters – WebHiearchicalDataGrid object, column key and separator character and returns a string in which selected values are separated by that character (if nothing is passed – default separator is comma). Continue reading →