Skip to main content

Posts

Showing posts from February, 2014

Featured Post

How to use Tabs in ASP.NET CORE

I want to show Components in a tabs , so first of all create few components. In this project we have three components, First View Component  public class AllViewComponent : ViewComponent     {         private readonly UserManager<ApplicationUser> _userManager;         public AllViewComponent(UserManager<ApplicationUser> userManager)         {             _userManager = userManager;         }         public async Task<IViewComponentResult> InvokeAsync()         {             List<StudentViewModel> allUsers = new List<StudentViewModel>();             var items = await _userManager.Users.ToListAsync();             foreach (var item in items)             {                 allUsers.Add(new StudentViewModel {Id=item.Id, EnrollmentNo = item.EnrollmentNo, FatherName = item.FatherName, Name = item.Name, Age = item.Age, Birthdate = item.Birthdate, Address = item.Address, Gender = item.Gender, Email = item.Email });             }            

Decrement operator in c# programming

Those operator, which is used for decrement by one in any value known as decrement operator. These are two types. Pre-Decrement operator Post-Decrement operator  In pre-decrement operator appear before its operand, such as --a. Here "a" is a operand and -- is the decrement operator. In this case, value of the operand(a) will be decremented by one "after" it has been decremented. In post-decrement operator appear after its operand, such as a--. Similarly again, "a" is a operand and -- is the decrement operator.In this case, value of the operand(a) will be decremented by one "before" it has been decremented. Lets take an simple example of both pre and post decrement using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         {             double a;             a = 1.5;             Console.Wri

Merging the ordered Singly Linked List for Data Structure in 'C'

Merging the ordered Singly Linked List:          Often it is necessary to merge two linked lists into a single linked list. Merging of two arrays consumes lots of time and storage whereas merging of two linked lists is simple. Just changing the address stored in link field of each node as and when required carries out the merging in case of linked list. Let us consider the example as follows before dealing with algorithm and program. Both of the linked lists are in ascending order. First node address of each linked list is stored in ROOT1 and ROOT2 respectively. In order to merge these lists we can use another external pointer ‘ROOT’ to point to the first node of each list is compare. The node whose information is less become the first node of the merged list and the address of that node is stored in ‘ROOT’ .The process is continued till the end of each list. In the above example the information of the first node of the second list is smaller than that of first node of t

Default selection RadiobuttonList Example in ASP.NET

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default5.aspx.cs" Inherits="Default5" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title>Default selection</title> </head> <body>     <form id="form1" runat="server">     <div>         <asp:RadioButtonList ID="RadioButtonList1" runat="server" AutoPostBack="True"              onselectedindexchanged="RadioButtonList1_SelectedIndexChanged">             <asp:ListItem>Literal Control</asp:ListItem>             <asp:ListItem>Label Control </asp:ListItem>             <asp:ListItem>Localize control</asp:ListItem>             <asp:Lis

C# Programming: How to find pow of given number

You can easily find power of given number using Pow, which is static method of Math class. Here we take an example with integer number. Also gives II method , which is performed by programming. Both method include in single program using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         {             int a = 2, b = 4;                             Console.WriteLine(" The power of given number is {0}",Math.Pow(a, b));             // Second method         int result= Fun(2, 6);         Console.WriteLine(" The power of given number is {0}", result);             Console.ReadKey();         }         private static int Fun(int a, int b)         {             if (b >= 1)             {                 return (a * Fun(a, --b));             }             else              

c# programming : How to find largest number in given two number

You can easily find largest number between two number using Max, which is static method of Math class. This method is overload with multiple data types, such as Max(Byte, Byte) , Max(Decimal, Decimal) and many more data types. Here we take an example with integer number. using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         {             int a = -3, b = 52;             Decimal deci = -4, deci1 = 53;             Console.WriteLine(" the maximum number in between a= {0} and b={1} are {2}",a,b, Math.Max(a, b));             Console.WriteLine(" the maximum number in between a= {0} and b={1} are {2}", deci, deci1, Math.Max(deci, deci1));             Console.ReadKey();         }     } } Code generate the following output

C Program to reverse an ordered linked list for Data Structure for C Program

C Program to reverse an ordered linked list: struct node { inf info; struct node *link; };typedef struct node sn; sn*insert(sn *root, int i) { sn *new,*temp,*ptemp; new=(sn*)malloc(sizeof(sn)); if(new= =NULL) { printf(“Memory allocation error…”); exit(0); } new->info=I;new->link=NULL; if(root= =NULL) root=new; else if(i<root->info) { new->link=root;  root=new; } else { temp=root; while(temp=NULL&&i>temp->info) { ptemp=temp; temp=temp->link; } new->link=temp; ptemp->link=new; }return root; /*address of first node is returned*/ } void traverse(sn *ptr) { while(ptr!=NULL) { printf(“%d”,ptr->info); ptr=ptr->link; } } sn*reversell(sn *root) { sn *first=root,*pptr=root,*nptr; nptr=nptr->link; while(nptr!=NULL) { root=nptr; nptr=nptr->link; root->link=pptr; pptr=root; } first->link=NULL; return root; } main() { sn *root=NULL,*ptr;int info; char ch; while(1) { printf(“/nEnter

Reversing the ordered Singly Linked List for Data Structure in'C'

Special Operation on linked lists: Reversing the ordered Singly Linked List:               In order to reverse the ordered singly linked list, the root must point to the last node of the list. The first node’s address must be copied to the link of second node. Similarly the address of each node is copied in the link of the next node. It works like exchanging the links of each node with the address of the previous node. The algorithm is simple and self-explanatory. The same is given as follows: REVERSELL (ROOT) FIRST<--ROOT [To store the first node’s address] PPTR<--ROOT        [To store the address in link] NPTR<--ROOT-->LINK [To store address of previous node] Repeat While NPTR< >NULL   ROOT<--NPTR   NPTR<--NPTR-->LINK   ROOT-->LINK<--PPTR   PPTR<--ROOT [End of while] FIRST-->LINK<--NULL [To make first node as last] Return ROOT Exit.

How to Use Operators with Strings in Java Programming

Operator + with strings You have used the operator + with numbers. When you use + with numbers, the result is also a number. However, if you use operator + with strings, it concatenates them e.g. 5 + 6 results in to 11. “5” + “6” results in to “56”. “17” + “A, V. Vihar” result in to “17 A, V. Vihar” “abc” + “123” results in to “abc 123” “” + 5 + “xyz” results in to “5xyz” “” + 5 results in to “5” (In above two expressions Java would internally convert 5 in to “5” first and then concatenate with “xyz” and “” respectively.) Increment/Decrement Operators (++, --) Java includes two useful operators not generally found in other computer languages (expect C and C++). These are the increment and decrement operators, ++ and --. The operators ++ adds 1 to its operand, and – subtracts one. In other words, a = a + 1; is the same as ++a ; or a++; And a = a – 1 is the same as --a ; or a --; However, both the increment and decrements come in to two varieties: they may eithe

How to find absolute number of a given number in c# programming

In c# programming we easily find absolute number of a given number. We can use Abs function, which is include in Math class. Lets take an simple example using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace ConsoleApplication1 {     class Program     {         static void Main(string[] args)         {             sbyte sortbyte1 = -12, sortbyte2 = 12;             short shnumber1 = -13, shnumber2 = 13;             int integer1 = -14, integer2 = 14;             long long1 = -15, long2 = 15;             float float1 = -16.0f, float2 = 16.0f;             double double1 = -17.1, double2 = 17.1;             Decimal decimal1 = -18.0m, decimal2 = 18.0m;             Console.WriteLine();             Console.WriteLine("SortByte:   1) {0,-2} {1,-2}", Math.Abs(sortbyte1), Math.Abs(sortbyte2));             Console.WriteLine("Integer 16 bit:   1) {0,-2} 2) {1,-2}", Math.Abs(shnumber1), Math.Abs(shnumber2));      

Memory representation of Linked List Data Structures in C Language

                                 Memory representation of Linked List              In memory the linked list is stored in scattered cells (locations).The memory for each node is allocated dynamically means as and when required. So the Linked List can increase as per the user wish and the size is not fixed, it can vary.                Suppose first node of linked list is allocated with an address 1008. Its graphical representation looks like the figure shown below:       Suppose next node is allocated at an address 506, so the list becomes,   Suppose next node is allocated with an address with an address 10,s the list become, The other way to represent the linked list is as shown below:  In the above representation the data stored in the linked list is “INDIA”, the information part of each node contains one character. The external pointer root points to first node’s address 1005. The link part of the node containing information I contains 1007, the address of

About the Default Action Methods in MVC Controller

Earlier article was about to add a controller (Student) and create its default views (having the same name as default actions). In this article we will discuss about the Index action which is used to show the list of particular table in database or any list container. The index action by default have following code: private StudentContext db = new StudentContext(); public ActionResult Index() { return View(db.Students.ToList()); } In this code the first line is used to create the object of Student context class, which is used further to perform CRUD actions with the database. This action is simply a method having return type ActionResult which is basically encapsulates the result of an action method and used to perform a framework-level operation on behalf of the action method. Just get in to the inner code of this action, having a single line of code, which is returning the view with the list of students stored in the database (from the db variable initialized in the fir

C Program to implement doubly linked list for Data Structrue in 'C'

C Program to implement doubly linked list: #include<stdio.h> #include<alloc.h> #include<stdlib.h> #include<conio.h> struct dlnode { Int info; struct dlnode *link; struct dlnode *prev; }; typedef struct dlnode dln; main( ) { dln *root, *temp, *new, *ptr; char choice=’y’; root=NULL; while(choice= =’y’) { new=(dln*)malloc(sizeof(dln); if(new= =NULL) { printf(“Memory allocation error…”); exit(0); } new->link=NULL; new->prev=NULL; printf(“\nEnter node information :”); scanf(“%d”,&new->info); if(root= =NULL) { root=new;    temp=root; } else { new->prev=temp;   temp->link=new; temp=new; } printf(“Do you want to continue…(y/n)”); choice=getche(); } printf(“\nDoubly linked list is:\n\n”); /* Doubly linked list normal singly linked list if it is traversed using link field of the node*/ ptr=root; while(ptr=NULL) { printf(“%d”,ptr->info); ptr=ptr->link; } printf(“\n\nDoubly linked list(reverse order):\n

Calculate duration between two dates in c# programming

Introduction Design simple age calculator , calculate remaining days from two dates. Suppose your Date of Birth is 19/mar/1987 and you want to calculate total days on till date. Here we take an simple demonstration of this type of application. Design Step-1 : Add two DateTimerPicker and one button control on windows form. Step-2 : Take Two Datetime class instance, first for starting date and second for ending date. Step-3 :  Calulate difference between two dates using Timespan structure. Step-4 :  Using TotalDays property of TimeSpan structure you can calculate days. Code using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace datecalulator {     public partial class Form1 : Form     {         public Form1()         {             InitializeComponent();         }         private void button1_Click(o

Understanding creation of doubly linked list for Data Structrue in 'C'

Understanding creation of doubly linked list :                                                                                                    One node with information ‘6’ is added to the doubly linked list. Then the list become,                                                                                                                                                                                                                                                           Another node with information ‘16’ is added to the circular linked list. Then the list become, Similarly when two more nodes are added with information ‘1’ and ’61’, the list become, Traversing the Doubly Linked List        Set a pointer variable PTR with ROOT. Process PTR-->INFO and update PTR by LINK of PTR i.e. PTR<--PTR-->LINK. Repeat till the PTR is NULL. The algorithm is as follows:       TRAVERSDLL (ROOT)       PTR<--ROOT       Repeat While PTR< >NULL    

How to Create User-Defined Database in SQL Programming

In addition to system databases, the SQL Server also contains user-defined databases where the users store and manages their information. When the users create a database, it is stored as a set of files on the hard disk of the computer. To create a user-defined database, you can use the CREATE DATABASE statement. The syntax of the CREATE DATABASE statement is: CREATE DATABASE database_name [ON [ PRIMARY ] [ < filespec >]] [LOG ON [ < filespec >}} < filespec > : : = ( [ NAME = logical_file_name , ] FILENAME = ‘os_file_name’ [ , SIZE = size] [ , MAXSIZE = { max_size | UNLIMITED } ] [ , FILEGROWTH = growth_increment ] ) [ ,…n ] Where Database_name is the name of the new database. ON specifies the disk files used to store the data portion of the database (data files). PRIMARY specifies the associated <filespec> list that defines file in the primary filegroup. LOG ON specifies the disk files used to store the log files. NAME=logical_file_name sp

How to Identify the Database Files in SQL Server

In SQL Server programming context, each database is stored as a set of files on the hard disk of the computer. These files may be of following types including Primary data file The primary data file contains the database objects. The primary file can be used for the system tables and objects, and the secondary file can be used to store user data and objects. The primary data file has (.mdf) extension. Secondary data file The secondary data file also stores the database objects. Very large databases may need multiple secondary data files spread across multiple disks. Databases need not have secondary data files, if the primary data file is large enough to hold all the data in the database. The secondary data file has (.ndf) extension. Transaction log file The transaction log file records all modifications that have occurred in the database and the transactions that caused those modifications. At least one transaction log file holds all the transaction’s information and can be

Print one month later date in ASP.NET

You can use DateTime class for add months in current object of DateTime. DateTime class provides different types of methods to add this types of query like AddDays(), AddMonths() etc. This example cover AddMonth. Now take an simple example for that. Complete Code   <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default4.aspx.cs" Inherits="Default4" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">     <div>              <asp:Label ID="Label1" runat="server"></asp:Label>          </div>     </form> </body> </html> //code file using S

Doubly Linked List for Data Structure in C Programming

Doubly Linked List:  A little more variation to linear linked list gives another type of linked list called as doubly linked list. You might have observed in the linear list that every node contains two parts. One part contains the information and the other part contains the address of the next node in the list. If another pointer part is added to the node, to contain the address of previous node then the linear linked list becomes doubly linked list. In such lists you can traverse only in one direction. In the middle of traverse if you want to come back to the previous node it is not possible. The movement is one-way. It is possible to move in both the directions in doubly linked list. You can traverse in both the directions. This application of variation is very simple. The node in doubly linked list looks as follows: If the node is the first node of the list been previous pointer contains a NULL address because there are no previous nodes. If the node is the last node the

Searching In Circular linked list for Data Structure in 'C'

Searching:                In order to do searching in circular linked list, get the information to be searched and set PTR with ROOT. Compare Information with INFO of PTR, if it is equal ‘search is successful’ and terminate operation otherwise update PTR with LINK of PTR and repeat the process. Continue the operation till the end. The end is recognized by an address of first node given by ROOT stored in Link of PTR. Algorithm for searching:        SEARCHCLL(ROOT, IN)        [ROOT is starting address of Linked List and          IN is Information to search in Linked List]         PTR<--ROOT         If PTR = NULL Then:          Write: ‘Empty Circular linked list’          Exit.         [End of If]         Repeat While IN< >PTR-->INFO          If PTR-->LINK = ROOT Then:             Break          [End of If]          PTR<--PTR-->LINK          [End of while]          If PTR-->INFO = IN Then:            Write: ‘Search Successful’          Else:

Understanding traversing in circular linked list for Data Structure in 'C

Understanding traversing in circular linked list : Let us consider the following circular linked list. Let us assign a pointer PTR with ROOT, address of the first node. PTR is not equal to NULL. So, the circular linked list is not empty. Repeat while TRUE                 Write: PTR-->INFO    i.e. 6 is written                 PTR-->LINK is not equal to ROOT. So, no break.                 PTR<--PTR-->LINK     Now PTR points to second node                 Write: PTR-->INFO     i.e. 16 is written                 PTR-->LINK is not equal to ROOT. So, no break.                 PTR<--PTR-->LINK       Now PTR points to third node                 Write: PTR-->INFO        i.e.  1 is written                 PTR-->LINK is not equal to ROOT. So, no break.                 PTR<--PTR-->LINK        Now PTR points to third node                Write: PTR-->INFO         i.e. 61 is written                PTR-->LINK is equal to ROOT. So, break.

How to use Editor Ajax Control in ASP.NET

Editor control is a editor or you can say modifier, as a name suggest you can format article like bold. How to use Editor  Step-1 : Add Script Manager Control to the design page Step-2 : Add Editor control to the page. Step-3 : Add one button control also handle button_click event. Code View <%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %> <%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit.HTMLEditor" tagprefix="cc1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head runat="server">     <title></title> </head> <body>     <form id="form1" runat="server">     <asp:Scrip

Retrieve Record from Database using QueryString Parameter in ASP.NET

In my previous article, we already covered query string concepts . In this article, we will cover how to get record from database using query string parameter. For this types of problem, we will take two webform, first webform is used for sending querystring and pass into second web form. Design pattern Step-1 : Take two Web Form in solution explorer (default.aspx, default2.aspx) Step-2 :  Bind GridView on first page (default.aspx page) using SqlDataSource control . Step-3 : Check "select checkbox using show smart tag. Step-4 : Handle GridView SelectedIndexChanged event , also generate QueryString in it. look like protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)     {         Response.Redirect("~/Default2.aspx?id=" + GridView1.SelectedRow.Cells[1].Text);     } Step-5 : In second page( Default2.aspx), Bind form view using SqlDataSource with Query String parameter. Code view  Default.aspx with Default.aspx.cs page