How to use a counter in a XSL Loop (xsl:for-each)

To use a counter in a XSL For-Each block, you can use the position() function, the Counter starts at value 1.

Sample XSL

<xsl:for-each select="Order/Products/Product">
    <position><xsl:value-of select="position()"></xsl:value-of></position>
</xsl:for-each>

see also MSDN position Function

Please rate this snippet

How to get the selected row index in Devexpress Xtragrid Control using C# and VB.NET

To get the selected row index in Devexpress Xtragrid Control using C# and VB.NET you can use the snippet below.

Samples

Sample C#

Sample VB.NET

Compatibility: working .NET 2.0 working .NET 3.0 not tested .NET 3.5 not working .NET 4.0 not working .NET 4.5not working .NET 4.6

If you have any questions or suggestions feel free to rate this snippet, post a comment or Contact Us via Email.

Related links:

Please rate this snippet

How to use substring in IOS using Objective-C

To use substring in IOS using Objective-C you can use the snippet below.

Sample Objective-C

NSString *myString = @"http://codesnippets.fesslersoft.de";
NSString *myNewString = [myString substringFromIndex:7]; //myNewString will be "codesnippets.fesslersoft.de"

Please rate this snippet

How to remove columns from DataTable in C# and VB.NET

To remove columns from DataTable in C# and VB.NET you can use the snippet below.

Sample C#

DataTable dataTable;
dataTable.Columns.Remove("Columnname");
dataTable.Columns.RemoveAt(index);

Sample VB.NET

Dim dataTable As DataTable
dataTable.Columns.Remove("Columnname")
dataTable.Columns.RemoveAt(index)

Please rate this snippet

How to check if one one string contains another string in Javascript

To check if one one string contains another string in Javascript you can use the following method.

Sample JS

if(testString.indexOf("substring") > -1){
}

Please rate this snippet

IndexOf method for Javascript

With the snippet below you can use the IndexOf method for Javascript.

Sample JS

Array.prototype.IndexOf = Array.prototype.IndexOf || function (element) {
    for (var i=0; i < this.length; i++) {
        if(this[i] === element) return i;
    }
    return -1;
};

Please rate this snippet

AddToEnd listbox extension for C# and VB.NET

The simple but usefull AddToEnd listbox extension for C# and VB.NET.

Sample C#

public static void AddToEnd(this ListBox listbox, object data)
{
	listbox.Items.Add(data);
	listbox.TopIndex = listbox.Items.Count - 1;
	listbox.ClearSelected();
}

Sample VB.NET

<System.Runtime.CompilerServices.Extension> _
Public Shared Sub AddToEnd(listbox As ListBox, data As Object)
	listbox.Items.Add(data)
	listbox.TopIndex = listbox.Items.Count - 1
	listbox.ClearSelected()
End Sub

Please rate this snippet

How to get a word by index in C# and VB.NET

To get a word by index in C# and VB.NET you can use the following snippet.

Sample C#

public static string GetWordByIndex(string input, int index)
{
	try
	{
		var words = input.Split(' ');
		if ((index < 0) || (index > words.Length - 1))
		{
			throw new IndexOutOfRangeException("Index out of range!");
		}
		return words[index];
	}
	catch (Exception ex)
	{
		//handle the exception your way
		return string.Empty;
	}
}

Sample VB.NET

Public Shared Function GetWordByIndex(input As String, index As Integer) As String
	Try
		Dim words = input.Split(" ")
		If (index < 0) OrElse (index > words.Length - 1) Then
			Throw New IndexOutOfRangeException("Index out of range!")
		End If
		Return words(index)
	Catch ex As Exception
		'handle the exception your way
		Return String.Empty
	End Try
End Function

Please rate this snippet