Wednesday, 13 April 2016

Filter ArrayList value depend on datatype In C#


To get only specific Datatype value in ArrayList you can used below code .

OfType<DataType> ==> this is used to filter arraylist  value depend on DataType passed in.



          ArrayList list = new ArrayList();

            list.Add(1);
            list.Add(1.2);
            list.Add("StringValue");
            list.Add("StringValueOne");
            list.Add(true);

            foreach(var item in list.OfType<String or Int or Bool>()) // Here you can passed string,int ext  .
            {
                Console.WriteLine(item);
            }


Output: StringValue,StringValueOne

Monday, 4 April 2016

Find element whose id has a particular pattern in Jquery

Basically we have pattern to match with ID in jquery .


1) That selector matches all Button that have an id attribute and it starts with  "Test"

            $('input[id^="Test"]').css('background-color', 'red');
        

2)  That selector matches all Button that have an id attribute and it ends with "Test".

            $('input[id$="Test"]').css('background-color', 'red');
          

3) That selector matches all Button that have an id attribute  anywhere  with "Test" id.

            $('input[id*="Test"]').css('background-color', 'red');
         
Ex -> <asp:Button ID="Test" runat="server" Text="Button"  />
         <asp:Button ID="Test1" runat="server" Text="Button1" />
         <asp:Button ID="Test2" runat="server" Text="Button2" />
         <asp:Button ID="NotTest3" runat="server" Text="Button3" OnClick="Button1_Click"                   OnClientClick="return test();"/>

Output for 1 , 2 and 3 Pattern)