How to select an element with its name attribute in jQuery

To select an element with its name attribute in jQuery you can use the snippet below.

Samples

Javascript Sample

if you remove the div in div[name=”de.Fesslersoft.Testname”] you will get all elements with the specific name.

You can also have a look at this JSFiddle.

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 Remove duplicates from a IEnumerable using C# or VB.NET

To Remove duplicates from a IEnumerable using C# or VB.NET you can use the snippet below.

Sample .NET 3.5 and newer

Sample C#

using System;
using System.Collections.Generic;
using System.Linq;

namespace de.Fesslersoft.DistinctIenumerbable
{
    class Program
    {
        static void Main(string[] args)
        {
            var myList = new List<string>
            {
                "1A", "1A", "1B", "1C", "1C", "1D", "1D"
            };

            myList = myList.Distinct().ToList();

            foreach (var item in myList)
            {
                Console.WriteLine(item);
            }
            Console.Read();
        }
    }
}

Sample VB.NET (autogenerated)

Imports System.Collections.Generic
Imports System.Linq

Namespace de.Fesslersoft.DistinctIenumerbable
	Class Program
		Private Shared Sub Main(args As String())
			Dim myList = New List(Of String)() From { _
				"1A", _
				"1A", _
				"1B", _
				"1C", _
				"1C", _
				"1D", _
				"1D" _
			}

			myList = myList.Distinct().ToList()

			For Each item As var In myList
				Console.WriteLine(item)
			Next
			Console.Read()
		End Sub
	End Class
End Namespace

Sample .NET 2.0

Sample C#

using System;
using System.Collections.Generic;

namespace de.Fesslersoft.DistinctIenumerbable
{
    class Program
    {
        static void Main(string[] args)
        {
            List<String> myList = new List<string>();
            myList.Add("1A");
            myList.Add("1A");
            myList.Add("1B");
            myList.Add("1C");
            myList.Add("1C");
            myList.Add("1D");
            myList.Add("1D");

            var newList = new List<String>();
            foreach (var item in DistinctIenumerable(myList))
            {
                newList.Add(item);
            }

            foreach (var item in newList)
            {
                Console.WriteLine(item);
            }
            Console.Read();
        }

        internal static IEnumerable<T> DistinctIenumerable<T>(IEnumerable<T> input)
        {
            var passedValues = new Dictionary<T, bool>();
            foreach (T item in input)
            {
                if (!passedValues.ContainsKey(item))
                {
                    passedValues.Add(item, false);
                    yield return item;
                }
            }
        }
    }
}

Sample VB.NET (autogenerated)

Imports System.Collections.Generic

Namespace de.Fesslersoft.DistinctIenumerbable
	Class Program
		Private Shared Sub Main(args As String())
			Dim myList As List(Of [String]) = New List(Of String)()
			myList.Add("1A")
			myList.Add("1A")
			myList.Add("1B")
			myList.Add("1C")
			myList.Add("1C")
			myList.Add("1D")
			myList.Add("1D")

			Dim newList = New List(Of [String])()
			For Each item As var In DistinctIenumerable(myList)
				newList.Add(item)
			Next

			For Each item As var In newList
				Console.WriteLine(item)
			Next
			Console.Read()
		End Sub

		Friend Shared Function DistinctIenumerable(Of T)(input As IEnumerable(Of T)) As IEnumerable(Of T)
			Dim passedValues = New Dictionary(Of T, Boolean)()
			For Each item As T In input
				If Not passedValues.ContainsKey(item) Then
					passedValues.Add(item, False)
					yield Return item
				End If
			Next
		End Function
	End Class
End Namespace

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 Display an Image in Devexpress XtraGrid Control using C# and VB.NET

To Display an Image in Devexpress XtraGrid Control using C# and VB.NET see the example below.

Sample C#

#region

using System.Data;
using System.Drawing;
using System.Windows.Forms;
using WindowsFormsApplication77.Properties;
using DevExpress.XtraEditors.Repository;

#endregion

namespace de.fesslersoft.XtraGridImageTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            gridControl1.DataSource = CreateTable(3);
            gridView1.Columns["Image"].ColumnEdit = new RepositoryItemPictureEdit();
        }

        private DataTable CreateTable(int rowCount)
        {
            var image = Resources.Image1;
            var tbl = new DataTable();
            tbl.Columns.Add("ID", typeof (int));
            tbl.Columns.Add("URL", typeof (string));
            tbl.Columns.Add("Image", typeof (Image));
            for (var i = 0; i < rowCount; i++)
            {
                tbl.Rows.Add(new object[] {i, "http://codesnippets.fesslersoft.de", image});
            }
            return tbl;
        }
    }
}

Sample VB.NET

#Region ""

Imports System.Data
Imports System.Drawing
Imports System.Windows.Forms
Imports WindowsFormsApplication77.Properties
Imports DevExpress.XtraEditors.Repository

#End Region

Namespace de.fesslersoft.XtraGridImageTest
	Public Partial Class Form1
		Inherits Form
		Public Sub New()
			InitializeComponent()
			gridControl1.DataSource = CreateTable(3)
			gridView1.Columns("Image").ColumnEdit = New RepositoryItemPictureEdit()
		End Sub

		Private Function CreateTable(rowCount As Integer) As DataTable
			Dim image = Resources.Image1
			Dim tbl = New DataTable()
			tbl.Columns.Add("ID", GetType(Integer))
			tbl.Columns.Add("URL", GetType(String))
			tbl.Columns.Add("Image", GetType(Image))
			For i As var = 0 To rowCount - 1
				tbl.Rows.Add(New Object() {i, "http://codesnippets.fesslersoft.de", image})
			Next
			Return tbl
		End Function
	End Class
End Namespace

Result

XtraGrid ColumnImages

XtraGrid ColumnImages


Please rate this snippet

How to get return Value from method invocation using reflection in C# and VB.NET

To get return Value from method invocation using reflection in C# and VB.NET you can use the snippet below.

Sample C#

var returnValue = (Int32)methodInfo.Invoke(null,null); //just cast the returned object of Invoke to the needed Type. Theres no difference if it is a static method/class or not

Sample VB.NET

Dim returnValue = DirectCast(methodInfo.Invoke(Nothing, Nothing), Int32) 'just cast the returned object of Invoke to the needed Type. Theres no difference if it is a static method/class or not

For more informations on how to invoke methods from other assemblies using reflection see:

  • How to call a static method in different assembly using Reflection in C# and VB.NET
  • How to call a non-static method in different assembly using Reflection in C# and VB.NET
  • Please rate this snippet

    How to check if an array contains a value in Javascript

    To check if an array contains a value in Javascript you can use the snippet below.

    Sample Javascript

    Array.prototype.inArray = function (inputValue) {
    	var counter;
    	for (counter=0; counter < this.length; counter++) {
    		if (this[counter] === inputValue) {
    			return true;
    		}
    	}
    	return false;
    };
    

    Please rate this snippet

    IsNull extension method for C# and VB.NET

    You can use the IsNull Extension method by using the snippet below.

    Sample C#

    public static bool IsNull(this object source)
    {
         return source == null;
    }
    

    Sample VB.NET

    <System.Runtime.CompilerServices.Extension> _
    Public Shared Function IsNull(source As Object) As Boolean
    	Return source Is Nothing
    End Function
    

    As always, this extension method has been added to the Github Fesslersoft.Extensions Repository

    Please rate this snippet

    How to get element with the highest ID using XSL

    To get element with the highest ID using XSL you can use the following snippet.

    XML:

    <rootnode>
        <node>
            <id>3</id>
        </node>
        <node>
            <id>2</id>
        </node>
        <node>
            <id>1</id>
        </node>
    	<node>
            <id>5</id>
        </node>
        <node>
            <id>4</id>
        </node>
    </rootnode>
    

    XSL:

    <xsl:variable name="MaxNodeId"><xsl:value-of select="/rootnode/node[not(/rootnode/node/id > id)]/id"/></xsl:variable>
    

    Please rate this snippet