Friday, 18 December 2015

Javascript Event( On Button Click)

JavaScript Example :-

Show POP-UP Message On Button Click


Event :- On Button Click 


Message :- "Hello World" 

Source Code:-
--------------------------------------------------------
<!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 myFunction() {
            alert("Hello World");
        }
    </script>
</head>
<body>
    <form id="form1" runat="server">
   <h1>Javascript Example</h1>
   <p>Click On Button </p>
    <button onclick="myFunction()">
        Try it</button>
    <p id="demo">
    </p>
    </form>
</body>
</html>
--------------------------------------------------------
See Image :- 




--------------------------------------------------------



Example of using LINQ to SQL Database connection in Asp.Net

Example of using LINQ to SQL Database connection in Asp.Net

Step-1 :- Design Page like this



Source Code :-  
---------------------------------------

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>On Click Events</title>
</head>
<body>
    <form id="form1" runat="server">
    <div id="Main">
        <div>
            <table style="width:60%">
                <tr>
                    <td>
                        NAME
                    </td>
                    <td>
                        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        Company
                    </td>
                    <td>
                        <asp:TextBox ID="txtCompany" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                    <td>
                        City
                    </td>
                    <td>
                        <asp:TextBox ID="txtCity" runat="server"></asp:TextBox>
                    </td>
                </tr>
                <tr>
                <td></td><td><asp:Button ID="btnsave" Text="save" runat="server"
                        onclick="btnsave_Click" /></td>
                </tr>
                <tr>
                <td></td><td>
                    <asp:Label ID="lblmsg" runat="server" Text="msg" Visible="false"></asp:Label></td>
                </tr>
            </table>
        </div>
        <div>
        <p>Show the Data</p>
            <table style="width:100%">
                <tr>
                    <td>
                    </td>
                    <td>
                        <asp:GridView ID="grv1" runat="server">
                        </asp:GridView>
                    </td>
                    <td>
                    </td>
                </tr>
            </table>
        </div>
        <div id="footer">
            <p style="text-align:left">
                @ Design By Dot Net By Vickypedia</p>
        </div>
    </div>
    </form>
</body>
</html>

---------------------------------------

Step-2 :- Create Table "tblEmp"

Source Code :-  
---------------------------------------

Create Table tblEmp
(
    ID int identity(1,1) primary key,
    Name varchar(50),
    Company varchar(50),
    City varchar(50),
)

---------------------------------------

Step-3 :-  Add DBML Class in Application



Step-4 :- After then drag table "tblEmp" on DBML Class





Step-5 :-then write code for the Button "btnSave" 
              and GridView  "grv1"

Source Code :-  
---------------------------------------
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace JavaScriprt_Examples
{
    public partial class firstPage : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                ShowGrid();
            }
        }
        EmpDataBaseDataContext _eDBobj = new EmpDataBaseDataContext();

        protected void btnsave_Click(object sender, EventArgs e)
        {
            tblEmp tblEmpObj = new tblEmp();
            tblEmpObj.Name = txtName.Text;
            tblEmpObj.Company = txtCompany.Text;
            tblEmpObj.City = txtCity.Text;

            _eDBobj.tblEmps.InsertOnSubmit(tblEmpObj);
            _eDBobj.SubmitChanges();
            lblmsg.Visible = true;
           lblmsg.Text = "Add Successfully";
           clearform();
       
        }

        protected void clearform()
        {
            txtName.Text = "";
            txtCompany.Text = "";
            txtCity.Text = "";
        }


        protected void ShowGrid()
        {
            var v = from m in _eDBobj.tblEmps select m;
            grv1.DataSource = v;
            grv1.DataBind();
        }
    }
}
---------------------------------------

Step-6 :- Run the Application 







Thursday, 17 December 2015

hello world program in C#

Hello World -- Your First Program in Console Application



Use Console Application
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello, world!");
            Console.ReadLine();
        }
    }
}

Monday, 14 December 2015

Function in SQL with Example

Function in SQL with Example

In SQL function is a Stored Program that you can pass parameters into and returns a value. 

A function must always return a value & but a procedure may or may not return a value.

Example :- (Return a single value from a Customer Table.)
------------------------------------------------
Create table Customer
 (
   SrNo  int identity(1,1) primary key,
   Name Varchar(50),
   Age  varchar(50),
   ContactNo varchar(50)
)
------------------------------------------------



Create Function 
----------------------------------------------

Create FUNCTION FUN1
(
-- Add the parameters for the function here
@id int
)
returns varchar(50)
as
BEGIN

-- Declare the return variable here
DECLARE @Name varchar(50)

-- Add the T-SQL statements to compute the return value here
SELECT @name=Name from Customer WHERE SrNo= @id

-- Return the result of the function
Return  @name


END
----------------------------------------------


Execute Function
----------------------------------------------
select dbo.fun1(1)
----------------------------------------------

Output/Result :-













Sunday, 13 December 2015

Create Button at Run time on button click by Java Script

Create Button at Run time on button click by Java Script

Source Code :-

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title></title>
</head>
<body>
    <p> Click the button to make a BUTTON element with text.</p>
    <button onclick="myFunction()">
        Try it</button>
    <script type="text/javascript">
        function myFunction() {
            var btn = document.createElement("BUTTON");
            var btn1 = document.createTextNode("CLICK Here");
            btn.appendChild(btn1);
            document.body.appendChild(btn);
        }
    </script>
</body>
</html>

OutPut :-















Sunday, 6 December 2015

Ternary Operator in C#

Ternary Operator in C#

Ternary operator:-
The Ternary operator is not a type of conditional statement but it is also used to check the conditions. It returns only one value based on conditions. Use the ternary operator to check many values in a single line of coding.

Syntax:-

Variable = condition ? True Part : False Part;





Conditional Operator:-
The conditional operator (?:) returns one of two values depending on the value of a Boolean expression. Following is the syntax for the conditional operator.

Syntax:-

Variable = condition ? first_expression : second_expression;


Source Code :-

static void Main(string[] args)   
{  
    int a, b, Value;  
    a = 100;  
    b = 50;  
    Value = a > b ? a : b ;  
    Console.WriteLine("Greater Value:" + Value);  
    Console.Read();  
} 

Output:-
      Greater Value:100          





Factorial of a Number

Recently Viewed