Posts

Jquery serer side datatables in asp.net

In this post we will learn how we can implement jquery   server side datatables in asp.net mvc application. We need to add datatables library to our page, we can add references of libray from datatables <a href="https://datatables.net/" target="_blank">website</a>. We need to create an html table on which we will apply datatable. <table class="table table-striped table-bordered table-hover table-checkable order-column dataTable" id="tblInventoryItems">   <thead>     <tr>       <th>Item Name</th>       <th>Item Price</th>       <th>Item Quantity</th>       <th></th>     </tr>   </thead>   <tbody></tbody> </table> Then we need the code which will apply the datatable to above html table. Below is the code to apply datatable $("yourtableid").DataTable({         "proccessing": true,         "serverSide": true,  

Get elements by name in javascript

Getting elements by name attribute can done using getElementsByName method of document. This method takes value of name attribute as argument.  It returns array of elements because more than one element(s) can have same name. < input type ="button" value ="Get By Name" onclick =" GetByName() " /> < input type ="text" name ="txtNumber" /> < input type ="text" name ="txtNumber" /> < input type ="text" name ="txtNumber" /> < script type ="text/javascript">    function GetByName() {         var elements = document.getElementsByName( "txtNumber" );         if (elements.length > 0) {             alert(elements[0].value);         }         else             alert( "No matching element found" );     }   </ script >

Get elements by class name in javascript

To get elements using class name we use getElementsByClassName method available with document object. This method takes name of class an argument.  It returns array of elements because more than one element(s) can have same class. < input type ="button" value ="Get By Class" onclick =" GetByClassName() " /> < div id ="myDiv" class ="myClass">     This is a div </ div > < script type ="text/javascript">   function GetByClassName() {         var elements = document.getElementsByClassName( "myClass" );         if (elements.length > 0) {             alert(elements[0].innerHTML);         }     else       alert( "No matching element found" );    }   </ script >

Getting element by id in javascript

To get an element by its id we use getElementById method available with document object. It takes Id of element which we want to target. If element is not found it returns null. < input type ="button" value ="Get By Id" onclick =" GetByID() " /> < div id ="myDiv">     This is a div </ div > < script type ="text/javascript"> function GetByID() {   var element = document.getElementById( "myDiv" );    if (element != null ) {    alert(element.innerHTML);   } } </ script >

Reverse array in C#

To reverse an array we can use Reverse method of Array class. Overloads This method has two overloads. First overload takes an array as parameter which will be reversed. Second overload takes 3 parameters. First is array second is start index from where to start and third is length. string []arr = new string [3]; arr[0] = "One" ; arr[1] = "Two" ; arr[2] = "Three" ; Console .WriteLine( "Array before reversing" ); foreach ( string str in arr) {     Console .WriteLine(str); } Array .Reverse(arr); Console .WriteLine( "Array after reversing" ); foreach ( string str in arr) {     Console .WriteLine(str); } Output Array before reversing One Two Three Array after reversing Three Two One             

Using string array in C#

To create a stirng array we can define array of string type and length of array. string []arr = new string [5]; We can assign value to array by using index of array. Similarly we can get value by using index of array. Assigning value to array arr[0] = "One" ; arr[1] = "Two" ; arr[2] = "Three" ; arr[3] = "Four" ; arr[4] = "Five" ; Getting value from array string val = arr[2];

Get character array from string in C#

To get a  char  array from string we use ToCharArray method. Overloads This method has one overload which takes two parameters. First is StartIndex and second is Length. Return Type Return type of this method is  char  array. string str = "I like rain" ; char [] arr = str.ToCharArray(); foreach ( char c in arr) {   Console .WriteLine(c); }