Sunday, 28 February 2016

How to select multiple rows in a table.

In this example i will explain how to select multiple table rows by shift key by using Jquery.

<html>
<head></head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>

<script>
$(document).ready(function(){

$("#tableStudent tr").click(function(){
$(this).toggleClass("selected"); // add or remove class to table row
var TotalTrs = $("#tableStudent").children('tbody').children('tr'); // getting the totle rows in a table
if (window.event.shiftKey) {
lastSelectedRow = this;
// if the current row index is less than the first selected row index then interchange  indexes
if(firstSelectedRow.rowIndex > lastSelectedRow.rowIndex)
{
lastSelectedRow.rowIndex = firstSelectedRow.rowIndex;
 firstSelectedRow.rowIndex= lastSelectedRow.rowIndex;
}
for(var i=  firstSelectedRow.rowIndex;i<= lastSelectedRow.rowIndex;i++)
{
TotalTrs [i-1].className="selected";
}
}

else {
firstSelectedRow=this;
}

});

});

</script>

<style>
.selected
{
background-color:red;
}
</style>



<table id="tableStudent" border="1">
    <thead>
        <tr>
            <th>ID</th>
            <th>Name</th>
            <th>Class</th>
        </tr>
    </thead>
    <tbody>
        <tr >
            <td>1</td>
            <td>John</td>
            <td>4th</td>
        </tr>
         <tr >
            <td>2</td>
            <td>Jack</td>
            <td>5th</td>
        </tr>
         <tr >
            <td>3</td>
            <td>Michel</td>
            <td>6th</td>
        </tr>
        <tr >
            <td>4</td>
            <td>Mike</td>
            <td>7th</td>
        </tr>
        <tr >
            <td>5</td>
            <td>Yke</td>
            <td>8th</td>
        </tr>
         <tr >
            <td>6</td>
            <td>4ke</td>
            <td>9th</td>
        </tr>
        <tr >
            <td>7</td>
            <td>7ke</td>
            <td>10th</td>
        </tr>
    </tbody>
</table>
</body>
</html>

Friday, 5 September 2014

How to call a base class method even derived class object is created.

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

namespace InheritenceExample
{
class Program
{
static void Main(string[] args)
{
b obja = new b();
obja.Method1();
Console.ReadLine();
}
}


public class a
{
public virtual void Method1()
{
Console.WriteLine("base class method is called.");
}
}

public class b : a
{
public override void Method1()
{
base.Method1(); // calling base class method.
}
}

}
Result :  Base class method is called.

Interview Quations


Q1. Can we access the static webservice method by using Json ?

ANS. No

Q2. How to bind dropdownlist using  each function in jquery ?

ANS.    

                      <select id="ddlProducts"> </select> //html control
// jquery
            $("#ddlProducts").append($('<option>').text('select').attr('value', 0));
            $.each(data.d, function (i, item) {
            $('#ddlProducts').append($('<option>').text(item.ProductName).attr('value', item.ProductID));

Monday, 28 July 2014

What is MVC ?

Inter View Questions on MVC

what is MVC?

MVC stands for Modal View Controller.  MVC is a design pattern which using using for developing an application.

What is Design Pattern?

Design Pattern is a pre-Defined solution for a problem which is occurred in the application.

Note : MVC comes under architectural design pattern category. 

Thursday, 3 July 2014

Googe charts

 <script type="text/javascript" src="https://www.google.com/jsapi"></script>
    <script type="text/javascript">



     
        google.load('visualization', '1.0', { 'packages': ['corechart'] });      
        google.setOnLoadCallback(drawChart);
        function drawChart() {
         
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "webservice.asmx/test",
                data: "{'test':'test1'}",
                dataType: "json",
                success: function (response) {
                    drawVisualization(response.d);
                },
                error: function (response) {
                    alert("Error accured while updating item Status.");
                }
            });

        }

        function drawVisualization(dataValues) {        
            var data = new google.visualization.DataTable();
            data.addColumn('string', 'CustomerName');
            data.addColumn('number', 'POHeaderID');
            for (var i = 0; i < dataValues.length; i++) {            
                data.addRow([dataValues[i].CustomerName, dataValues[i].POHeaderID]);
            }        
            var options = { 'title': 'PO List',
                'width': 400,
                'height': 300
            };

            // Instantiate and draw our chart, passing in some options.
            var chart = new google.visualization.PieChart(document.getElementById('chart_div'));
            chart.draw(data, options);
        }
    </script>

What is Dot Net Framework

1. What is dot net framework?

2. How compilation works in .net ?

3. What is IL Code?

4. Different parts of .net frame work ?

· What is dot net frame work?

Dot net frame work is a platform which contains some libraries, some utilities, some compilers L+U+G which we can use developing , building and deploying varies dot net applications, web applications, windows applications, WCF applications, WPF applications

· How compilation works in dot net?

Compilation works in dot net works in two stages

ü Normal dot net code(C#,VB.Net) converted into IL(Intermediate language) by using compilers.

C# converted into IL by using CSC(c# compiler)

VB.net converted into IL by using VBC (VB compiler)

(IL is the half compiled code and IL is same for all the languages)

C# code = IL Code = VB code

ü IL con be taken by CLR (Common Language Runtime) and passed to JIT(Just In Compiler)

JIT is the responsible for convert the IL code to machine code.

· What is IL?

IL is nothing but a half compiled code(MSIL Microsoft Intermediate language)

JIT will get the control over the IL Code by sing CLR.

This JIT converted the Compiled code (IL) to machine code which is can be understand by operating system(machine code).

· Different parts of .Net framework.

clip_image001[4]

CLR Responsibilities

§ Converted IL Code into machine Code

§ Garbage collection.

§ Thread management.

§ Security (Code Access Security CAS).

CLR Consists of CTS, CTS Consists of CLS(Common language specification)

clip_image002[4]CTS CLS

CLS is defines set of rules which is must followed by all the dot net compiled languages

Tuesday, 29 April 2014

How to disable the mouse right click


<script language="JavaScript" type="text/javascript">
        //Message to display whenever right click on website
        document.onmousedown = disableclick;

        status = "Right click option is not allowed";

        function disableclick(e) {
            if (event.button == 2) {
                alert(status);
                return false;
            }
        }
   
    </script>

Wednesday, 19 February 2014

How to Generate sample Excel file in C#

ASP.Net

<body>
    <form id="form1" runat="server">
    <div>
    <asp:Button runat="server" ID="btnExcel" Text="Generate Excel" OnClick="btnExcel_Click" />
    </div>
    </form>
</body>



Backend Code:


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Reflection;
using Microsoft.Office.Interop.Excel;

namespace Excelgeneration
{
    public partial class ExcelGeneration : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnExcel_Click(object sender, EventArgs e)
        {
            GenerateExcel();
        }

        #region GenerateExcel
        public void GenerateExcel()
        {
            Application oXL = new Application();
            Workbook WB = null;
            Worksheet WS = null;
            Range oRng;

            oXL.Visible = true;
            // creating workbook
            //--------------------
            WB = (Workbook)(oXL.Workbooks.Add(Missing.Value));

            //Create work sheet
            WS = (Worksheet)(WB.ActiveSheet);

            //save the Excel File
            // -----------------------
            WB.SaveAs(@"D:\Excelfiles\Srinivas5", XlFileFormat.xlWorkbookDefault);

            // F:\Desktop is the file path
            // srinivas is the file name  

            //oXL.UserControl = true;


        }
        #endregion
    }
}




Sunday, 8 December 2013

What is smart navigation?

What is smart navigation? 
The cursor position is maintained when the page gets refreshed due to the server side validation and the page gets refreshed.

Wednesday, 6 November 2013

Parameters in Procedure and Functions


How to pass parameters to Procedures and Functions in PL/SQL?

In PL/SQL, we can pass parameters to procedures and functions in three ways.
1) IN type parameter: These types of parameters are used to send values to stored procedures.
2) OUT type parameter: These types of parameters are used to get values from stored procedures. This is similar to a return type in functions.
3) IN OUT parameter: These types of parameters are used to send values and get values from stored procedures.
NOTE: If a parameter is not explicitly defined a parameter type, then by default it is an IN type parameter.



Wednesday, 21 August 2013

How to create menu dynamically in Asp.Net Using Jquery.

In this article i will explain how to create a menu dynamically using jquery. The menu will create after click event of a button.

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>

<!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>
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"> </script>
</head>
<body>
    <form id="form1" runat="server">
    <div id="htmltabs">
    </div>
    <style type="text/css">
        ul#tab
        {
            margin: 0;
            padding-left: 10px;
            list-style-type: none;
            background-image: url[ 'http://www.galaxyfinishingschool.com/images/coursepic-dotnet.jpg' ];
        }
        ul#tab li
        {
            display: inline;
            padding-left: 10px;
            text-decoration: none;
        }
        a
        {
            text-decoration: none;
            background-color: Gray;
            font-size: 20px;
            color: White;
        }
    </style>
    <script type="text/jscript">
        $(document).ready(function () {
            $("#btnTest").click(function () {
                var str1 = '<span>srinu</span>';
                var str = '<ul id="tab"><li ><a href="http://dotnettutorialblog.blogspot.in/">Dot Net Blog</a></li><li ><a href="https://www.google.co.in/" >GooGle</a></li><li ><a href="https://www.yahoo.com/" >Yahoo</a></ul>';
                $("#htmltabs").html(str);
                $("#btnTest").css("display", "none");

            });
        });
    </script>
    <input type="button" id="btnTest" value="Get Menu" />
    </form>
</body>
</html>

Thursday, 15 August 2013

How to Replace substring in a string.

 

Here i will give an example how to replace a substring in a string. For example you want to change email address in employee details table. 

In below example i am replacing  EmailId  from “@gmail.com” to ‘”@yahoo.com” in Employee Table .

-- Exmple 01.

declare @txt1 varchar(50)
set @txt1 = 'srinu.munagala33@gmail.com'
-- Here iam replacing @gmail.com to @yahoo.com
set @txt1 = REPLACE(@txt1, '@gmail.com', '@yahoo.com')

select @txt1
-- out put
-- srinu.munagala33@yahoo.com
-- Exmple 2.
/*
You can also update employee emailid in employee table.
*/

-- before EmailID = srinu.munagala33@gmail.com

update EmployeeDetals
set EmailID = REPLACE(EmailID, '@gmail.com', '@yahoo.com')
where EmployeeCode = 3151

-- After updating EmailID = srinu.munagala33@yahoo.com

Wednesday, 10 July 2013

How to Execute C# Program using command prompt

 

 

Open Notepad

Write a sample program

 

image

 

Write bellow code in notepad and save as Test.cs

 

 

 

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N number");
            int n = Convert.ToInt32(Console.ReadLine());
            int i = 0, sum=0;
            for (i = 0; i <= n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine(sum);
            Console.ReadLine();

        }
    }
}

save this file in C Drive.

Next open Visula Studio Command prompt.

set the directory in Visual studio Command Prompt

 

image

 

now enter

C:\>CSC Test.cs

image

Enter

image

Enter N

3

Then the result

0+1+2+3= 6

image

Tuesday, 9 July 2013

Find The sum of N numbers

 

 

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

namespace ConsoleApplication3
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter N number");
            int n = Convert.ToInt32(Console.ReadLine());
            int i = 0, sum=0;
            for (i = 0; i <= n; i++)
            {
                sum = sum + i;
            }
            Console.WriteLine(sum);
            Console.ReadLine();

        }
    }
}

Monday, 8 July 2013

Find age or number of years between Two dates:

 

 

<%@ Page Language="C#" AutoEventWireup="true"  CodeFile="Default.aspx.cs"
Inherits="_Default" %>

<!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>Age</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <table>
    <tr>
    <td>
    BirthDaydate:
    </td>
    <td>
        <asp:TextBox runat="server" ID="txtBirthDayDate" ></asp:TextBox>
    </td>
    <td>
    Number Of days:
    </td>
    <td>

    <asp:TextBox runat="server" ID="txtResult"></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td colspan="3">
<asp:Button runat="server" ID="btnDays" OnClick="CountNumberOfdays_Click" Text="CheckDates" />
    </td>
    </tr>
    </table>


   
    </div>
    </form>
</body>
</html>

 

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class _Default : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void CountNumberOfdays_Click(object sender, EventArgs e)
    {

        DateTime date = Convert.ToDateTime(txtBirthDayDate.Text);
      
        DateTime BirthDayDate = new DateTime(date.Year, date.Month, date.Day);
        DateTime Todaydate = DateTime.Now;

        TimeSpan ts = Todaydate - BirthDayDate;
        
        float differenceInDays = ts.Days;
        float age = differenceInDays / 365;

        txtResult.Text = age.ToString();
    }
}

 

Result:

Enter Date in first Text box:

1-02-2013

 

Age:

0.5123287

Sunday, 7 July 2013

confirm box in Javascript:

 

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Test" %>

<!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>

    <script type="text/javascript">
        function conformbox() {
            var x;
            var r = confirm("please click any one");
            if (r == true) {
                x = "Ok Continue";
            }
            else {
                x = "cansel";
            }
            document.getElementById("id").innerHTML = x;
        }
</script>
    

</head>
<body>
    <form id="form1" runat="server">
    <div>
    
<input type="button" value="click me" onclick="conformbox()" />
<p id="id" ></P>
    </div>
    </form>
</body>
</html>

Find the biggest number in an array:

 

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Test" %>

<!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>

    <script type="text/javascript">
        function srinu() {
            var ar = new Array();
            ar[0] = 6;
            ar[1] = 4;
            ar[2] = 17;
            ar[3] = 3;
            ar[4] = 11;
            ar[5] = 10;
            var max = ar[0];

            for (var i = 1; i < ar.length; i++) {

                if (max < ar[i]) {
                    max = ar[i];
                }
                
            }
            alert(max);
           

        }
</script>
    

</head>
<body>
    <form id="form1" runat="server">
    <div>
    
<input type="button" onclick="srinu()" value="click me" />
    </div>
    </form>
</body>
</html>

Count the number of checked box checked:

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Test.aspx.cs"
Inherits="Test" %>

<!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>


    <script type="text/javascript" >
        function srinu() {
            var i;
            var count = 0;

            for (i = 1; i <= 4; i++) {
                var str = "c" + i;
                if (document.getElementById(str).checked == true) {
                    count++;
                }
            }
            alert(count);
        }
</script>
</head>
<body>
    <form id="form1" runat="server">
    <div>
    <input type="checkbox" id="c1"  value="1">fierst checkbox<br/>
<input type="checkbox" id="c2"  value="2">second checkbox<br/>
<input type="checkbox" id="c3"  value="3">third checkbox<br/>
<input type="checkbox" id="c4"  value="4">four checkbox<br/>
<input type="button" onclick="srinu()" value="click me" />
    </div>
    </form>
</body>
</html>

Friday, 5 July 2013

Prime Number Between Two numbers:

 

 

 

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

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Enter Two Numbers");
            Console.WriteLine("Enter First Number");
            int i = Convert.ToInt32(Console.ReadLine());
            Console.WriteLine("Enter second number");
            int j = Convert.ToInt32(Console.ReadLine());
            for (int k = i; k <= j; k++)
            {
                int count = 0;
                for (int l = 1; l <= k; l++)
                {

                    if (k % l == 0)
                    {
                        count++;
                    }

                }
                if (count == 2)
                {
                    Console.WriteLine(k);
                }
            }
            Console.ReadLine();


        }
    }
}

Monday, 1 July 2013

Login Example page

 

In this article i will give simple Login page.  It may be very useful for beginners. if you have any queries feel free to ask me.

1. Create a login table

2. Insert User names and passwords into login table.

3. Design login page . Take two TextBoxes , one button and one result label.

4. Write code for Onclick Event in Login.cs  file.


    -- CREATE LOGINTABLE
    CREATE TABLE LOGINTABLE
    (
    USERNAME VARCHAR(50),
    PASSWORD VARCHAR(50)
    )

    -- INSERT INTO LOGINTABLE

    INSERT INTO LOGINTABLE VALUES
                                (
                                'srinu.munagala33@gmail.com',
                                '07m11a1233'
                                )

SELECT * FROM LOGINTABLE

 

USERNAME PASSWORD
srinu.munagala33@gmail.com 07m11a1233

 

 

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="testLogin._Default" %>

<!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>
    <table align="center" >
    
    <tr>
    <td colspan="2">

    <span> Login </span>
    
    </td>
    </tr>
    <tr>
    <td>
    <span>User Name</span>
    </td>
    <td>
    <asp:TextBox runat="server" ID="txtUserName" Width="180px" ></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td>
    <span>Password</span>
    </td>
    <td>
    <asp:TextBox runat="server" ID="txtPassword" Width="180px" TextMode="Password" ></asp:TextBox>
    </td>
    </tr>
    <tr>
    <td colspan="2" align="center">
    <asp:Button runat="server" ID="btnSubmit" Text="Login" OnClick="login_Submit" />
    
    </td>
    
    </tr>
    <tr>
    <td align="center" colspan="2">
    <asp:Label runat="server" ID="lblResult" style=" color:Red ; font-size:20px;" ></asp:Label>

    <span  ></span>
    </td>
    
    </tr>
    </table>
    </div>
    </form>
</body>
</html>

 

.Cs

 

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

namespace testLogin
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }


        protected void login_Submit(object sender, EventArgs e)
        {
            SqlConnection SqlCon = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog =Test;Integrated Security=True");

            try
            {
                SqlCon.Open();
                SqlCommand SqlCom = new SqlCommand("select count(*) from LOGINTABLE where userName ='" + txtUserName.Text + "' and password ='" + txtPassword.Text + "'", SqlCon);

                int i = Convert.ToInt32(SqlCom.ExecuteScalar());
                if (i > 0)
                {
                    lblResult.Text = "Login Success";
                }

                else
                {
                    lblResult.Text = "Please enter valied username and password";
                }
            }
            catch (Exception ex)
            {
                lblResult.Text = ex.Message;
            }
            finally
            {
                SqlCon.Close();
            }
        }
        
        }
    }