Tuesday, 7 February 2012

Add Record to Database using Empty Template and Footer Template and in gridview serch data through Autocomplete Extender

Source Code
 <%@ Page Language="C#" AutoEventWireup="true" CodeFile="AutoCompleteInGridView .aspx.cs" Inherits="AutoCompleteInGridView_" %>

<%@ Register assembly="AjaxControlToolkit" namespace="AjaxControlToolkit" tagprefix="asp" %>

<!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>
    <style type="text/css">
        .style1
        {
            width: 100%;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
     <asp:ScriptManager ID="ScriptManager1" runat="server">
    </asp:ScriptManager>
    <div>
  
        <asp:UpdatePanel ID="UpdatePanel1" runat="server">
            <ContentTemplate>
                <table class="style1">
                    <tr>
                        <td>
                            <asp:GridView ID="gv" runat="server" AllowPaging="True"
                                AutoGenerateColumns="False"
                                onselectedindexchanged="gv_SelectedIndexChanged" ShowFooter="True" >
                          
                                <Columns>
                                    <asp:TemplateField HeaderText="Name">
                                      <ItemTemplate>
                                       
                                              <asp:TextBox ID="TxtName" runat="server"  Enabled="true" Visible="true"></asp:TextBox>                                       
                                           <asp:AutoCompleteExtender ID="TxtName_AutoCompleteExtender" runat="server"
                                               DelimiterCharacters="" Enabled="True" ServiceMethod="GetName" MinimumPrefixLength="1" ServicePath="" TargetControlID="TxtName">
                                           </asp:AutoCompleteExtender>
                                        </ItemTemplate>                                     
                                   </asp:TemplateField>
                                   <asp:TemplateField HeaderText="Roll">
                                   <ItemTemplate>
                                   <asp:TextBox ID="Txtroll" runat="server" Text='<%# Eval("roll") %>' Enabled="true" Visible="true"></asp:TextBox>                                       
                                   </ItemTemplate>
                                 
                                   </asp:TemplateField>
                                  <asp:TemplateField HeaderText="Name">
                                    
                                      <ItemTemplate>
                                          <asp:Label ID="LblRollno" runat="server" Text='<%# Eval("roll") %>' Visible="false"></asp:Label>
                                              <asp:TextBox ID="TxtName1" runat="server" Text='<%# Eval("Name") %>' Enabled="true" Visible="true"></asp:TextBox>                                       
                                       
                                        </ItemTemplate>
                                      <FooterTemplate>
                                          <asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
                                      </FooterTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Age">
                                        <FooterTemplate>
                                            <asp:TextBox ID="Txtage" runat="server"></asp:TextBox>
                                        </FooterTemplate>
                                      <ItemTemplate>
                                       
                                              <asp:TextBox ID="Txtage" runat="server" Text='<%# Eval("age") %>' Enabled="true" Visible="true"></asp:TextBox>                                       
                                       
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField HeaderText="Date">
                                        <FooterTemplate>
                                            <asp:TextBox ID="TxtDate" runat="server"></asp:TextBox>
                                            <asp:CalendarExtender ID="TxtDate_CalendarExtender" runat="server"
                                                Enabled="True" TargetControlID="TxtDate">
                                            </asp:CalendarExtender>
                                        </FooterTemplate>
                                      <ItemTemplate>
                                       
                                              <asp:TextBox ID="Txtinfdate" runat="server" Text='<%# Eval("InfDate") %>' Enabled="true" Visible="true"></asp:TextBox>                                       
                                       
                                              <asp:CalendarExtender ID="Txtinfdate_CalendarExtender" runat="server"
                                                  Enabled="True" TargetControlID="Txtinfdate" Format="dd/MM/yyyy" ClearTime="false">
                                              </asp:CalendarExtender>
                                       
                                        </ItemTemplate>
                                    </asp:TemplateField>
                                    <asp:TemplateField >
                                        <FooterTemplate>
                                            <asp:Button ID="Btn_FInsert" runat="server" onclick="Btn_FInsert_Click"
                                                Text="Save" />
                                        </FooterTemplate>
                                    <ItemTemplate>
                                        <asp:Button ID="btnupdate" runat="server" Text="Update" CommandName="UP" OnClick="btnupdate_Click" />
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                     <asp:TemplateField>
                                    <ItemTemplate>
                                        <asp:Button ID="btndlt" runat="server" Text="Dlt" CommandName="UP"
                                            onclick="btndlt_Click"/>
                                    </ItemTemplate>
                                    </asp:TemplateField>
                                  
                                </Columns>
                             <EmptyDataTemplate>
        <tr style="background-color: Green;">
            <th scope="col">
                 Name
            </th>
            <th scope="col">
                Age
            </th>
            <th scope="col">
               Date
            </th>
            <th scope="col">
                 
            </th>
        </tr>
        <tr>
            <td>
                <asp:TextBox ID="txtName" runat="server" />
            </td>
            <td>
                <asp:TextBox ID="txtage" runat="server" />
            </td>
            <td>
                <asp:TextBox ID="txtdate" runat="server" />
            </td>
            <td>
                <asp:Button ID="btnAdd" runat="server" Text="Add" OnClick="Add" CommandName = "EmptyDataTemplate" />
            </td>
        </tr>
    </EmptyDataTemplate>
                            </asp:GridView>
                         
                        </td>
                    </tr>
                </table>
            </ContentTemplate>
            <Triggers>
            <asp:PostBackTrigger ControlID="gv" />
            </Triggers>
        </asp:UpdatePanel>
    </div>
 
     <asp:Label ID="Label1" runat="server" Text="Success"></asp:Label>
 
    </form>
</body>
</html>


Design

Runtime Design //When Blank Table
 

Runtime Design
 

C# Code
 using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
using System.Configuration;
public partial class AutoCompleteInGridView_ : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd = new SqlCommand();
    DataSet ds;
    SqlDataAdapter da;
    int roll;
    protected void Page_Load(object sender, EventArgs e)
    {
        Label1.Visible = false;
        if (IsPostBack == false)
        {
            con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
            //cmd.Connection = con;
            //cmd.CommandText = "select * from fms.fms_demo";
            con.Open();

            da = new SqlDataAdapter("select max(roll) as roll  from Student", con);
            ds = new DataSet();
            da.Fill(ds);
            if (ds.Tables[0].Rows[0]["roll"].ToString() != "")
            {
                roll = int.Parse(ds.Tables[0].Rows[0]["roll"].ToString());
                con.Close();
            }
            else
            {
                roll = 1;
            }
            fillGridview();
        }
    }

    private void fillGridview()
    {
        con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
        //cmd.Connection = con;
        //cmd.CommandText = "select * from
Student";
        con.Open();
        da = new SqlDataAdapter("select roll,Name,age,Convert(varchar(20),InfDate,111) as InfDate  from
Student", con);
        ds = new DataSet();
        da.Fill(ds);
        gv.DataSource = ds;
        gv.DataBind();
        con.Close();
    }
    [System.Web.Script.Services.ScriptMethod()]
    [System.Web.Services.WebMethod]
    public static List<string> GetName(string prefixText)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        con.Open();
        SqlCommand cmd = new SqlCommand("select * from
Student ", con);
        cmd.Parameters.AddWithValue("@Name", prefixText);
        SqlDataAdapter da = new SqlDataAdapter(cmd);
        DataTable dt = new DataTable();
        da.Fill(dt);
        List<string> CountryNames = new List<string>();
        for (int i = 0; i < dt.Rows.Count; i++)
        {
            CountryNames.Add(dt.Rows[i]["name"].ToString());
        }
        return CountryNames;
    }
    protected void btnupdate_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        Button bt = (Button)sender;
        GridViewRow gr = (GridViewRow)bt.NamingContainer;
        int rr = gr.RowIndex;

        Label t1 = (Label)gr.FindControl("LblRollno");
        TextBox t2 = (TextBox)gr.FindControl("TxtName1");
        con.Open();
        SqlCommand com = new SqlCommand("update
Student set Name='" + t2.Text + "' where roll=" + t1.Text + "", con);
        com.ExecuteNonQuery();
    }

   protected void Add(object sender, EventArgs e)
   {
    Control control = null;
    if (gv.FooterRow != null)
    {
        control = gv.FooterRow;
    }
    else
    {
        control = gv.Controls[0].Controls[0];
    }
    string nm = (control.FindControl("txtName") as TextBox).Text;
    int ag = int.Parse((control.FindControl("txtage") as TextBox).Text);
    DateTime dt =Convert.ToDateTime((control.FindControl("txtdate") as TextBox).Text);
    string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    using (SqlConnection con = new SqlConnection(strConnString))
    {
        using (SqlCommand cmd = new SqlCommand())
        {
            cmd.Connection = con;
            cmd.CommandType = CommandType.Text;
            cmd.CommandText = "INSERT INTO
Student (Name,age,InfDate) VALUES(@CustomerName, @Customerage, @Customerdob)";
            cmd.Parameters.AddWithValue("@CustomerName", nm);
            cmd.Parameters.AddWithValue("@Customerage", ag);
            cmd.Parameters.AddWithValue("@Customerdob", dt);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();
        }
    }
    Response.Redirect(Request.Url.AbsoluteUri);
}
    protected void gv_SelectedIndexChanged(object sender, EventArgs e)
    {

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

       SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        Button bt = (Button)sender;
        GridViewRow gr = (GridViewRow)bt.NamingContainer;
        int rr = gr.RowIndex;

        Label t1 = (Label)gr.FindControl("LblRollno");
       // TextBox t2 = (TextBox)gr.FindControl("TxtName1");
        con.Open();
        SqlCommand com = new SqlCommand("delete from
Student where roll=" + t1.Text + "", con);
        com.ExecuteNonQuery();
    }
    protected void Btn_FInsert_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
        Button bt = (Button)sender;
        GridViewRow gr = (GridViewRow)bt.NamingContainer;
        TextBox Nm = (TextBox)gr.FindControl("TxtName");
        TextBox ag = (TextBox)gr.FindControl("Txtage");
        TextBox dt = (TextBox)gr.FindControl("TxtDate");
        con.Open();
        SqlCommand com = new SqlCommand("Insert into
Student (age,InfDate,Name) values('"+ag.Text+"','"+dt.Text+"','"+Nm.Text+"')",con);
       int x= com.ExecuteNonQuery();
       if (x > 0)
       {
           fillGridview();
           Label1.Visible = true;
       }     
    }
}


Web Config File
<?xml version="1.0"?>
<configuration>
  <connectionStrings>
    <add name="ConnectionString" connectionString="server=Satya\S1;database=linku;uid=ma;pwd=li2011"/>
  </connectionStrings>
    <system.web>
   
        <compilation debug="true" targetFramework="4.0">
            <assemblies>
                <add assembly="System.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A"/>
                <add assembly="System.Web.Extensions.Design, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
                <add assembly="System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B77A5C561934E089"/></assemblies></compilation>
   
    </system.web>
</configuration>


Databse Design







Monday, 6 February 2012

What is WCF ? And Example.

This tutorial will guide you through creating and consuming your first WCF Service using Visual Studio 2008 and C#.NET


This tutorial was created with Microsoft Visual Studio .NET 2008 using WCF. WCF was implemented into the .NET Framework in 3.0, and received an update in 3.5, this tutorial is directed at users of Visual Studio.NET 2008 and ASP.NET 3.5
WCF (or Windows Communication Foundation) is a union of technologies developed by Microsoft to make it easier and quicker for developers to build distributed applications. WCF builds on the existing technologies of ASMX, .NET Remoting, MSMQ and DCOM. WCF attempts to unify these technologies and harness the power of all, while simplifying the process of implementation.
In this tutorial, we will show how to create a WCF Service, and how to consume it within an ASPX page. To demonstrate WCF, we will create a simple Operation Contract, which is similar to a Web Method, that we will call from our ASPX page. We can even expose the methods of the service to JavaScript, so that we can use them client-side.
To begin, create a new web application in Visual Studio. Then in Solution Explorer, right-click the Project and choose to Add New Item.. AJAX-enabled WCF Service, name it Service1. This should create a Service1.cs in the App_Code folder, and a Service1.svc in the root. Firstly, our .svc file will look like this:

<%@ ServiceHost Language="C#" Debug="true" Service="Service1" CodeBehind="~/App_Code/Service1.cs" %>
The Service1.cs file will look something like this:

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}

// Add more operations here and mark them with [OperationContract]
}
Need help with Windows Dedicated Hosting? Try Server Intellect. I'm a happy customer!
Notice the OperationContract attributes. We use this attribute to define the method as part of the WCF Service Contract.
Let's go ahead and add a simple method to demonstrate how to use it:

[OperationContract]
public static String Hello(String theString)
{
return "Hello, " + theString + ".";
}
Here, we are expecting an input parameter of type String, and we are also returning a String. A simple method to demonstrate how we can consume the WCF Service.
Going back to our ASPX page, we will create a Literal control, a TextBox control and a Button - all ASP controls:

<asp:TextBox ID="fld_String" runat="server" /><br />
<asp:Button ID="btn_Submit" runat="server" Text="Submit" OnClick="btn_Submit_Click" /><br />
<asp:Literal ID="lit_Display" runat="server" />
Nothing much different to a regular ASP.NET Web Application here. Notice we include the handler for the button. In the code-behind we will reference the Service to call the method we created earlier:

protected void btn_Submit_Click(object sender, EventArgs e)
{
lit_Display.Text = Service1.Hello(fld_String.Text);
}
Server Intellect assists companies of all sizes with their hosting needs by offering fully configured server solutions coupled with proactive server management services. Server Intellect specializes in providing complete internet-ready server solutions backed by their expert 24/365 proactive support team.
We did not wrap our Service1 class in a namespace, but in a real-world scenario it would most likely be beneficial to do so. If this was the case, we would have to reference the Service1 as Namespace.Service1, or simply add a using directive to the top of the page, using Namespace.Service1 for example.
Now if this application is run, you will see that we can input our name and upon button click, the WCF Service will be accessed and we will receive our return string. This all happens very quickly, but there is still a noticeable postback. We can work around this postback by AJAX-enabling the ASPX page, and also exposing the Service to Client-Side JavaScript.
To do this, we will need to add a Service reference to a ScriptManager on the page, like so:

<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Service1.svc" />
</Services>
</asp:ScriptManager>
By doing this, we make the ScriptManager manage all of our calls behind the scenes, and allow it to access the WCF Service we created earlier. This means that we can use Client-Side JavaScript to access the Methods of the Service. We will also add an UpdatePanel for the existing ASP.NET Controls, and then create some regular HTML form elements:

<form id="form1" runat="server">
<asp:ScriptManager ID="ScriptManager1" runat="server">
<Services>
<asp:ServiceReference Path="~/Service1.svc" />
</Services>
</asp:ScriptManager>

<asp:UpdatePanel ID="UP1" runat="server">
<ContentTemplate>
Call from Code-Behind:<br />
<asp:TextBox ID="fld_String" runat="server" /><br />
<asp:Button ID="btn_Submit" runat="server" Text="Submit" OnClick="btn_Submit_Click" /><br />
<asp:Literal ID="lit_Display" runat="server" />
<br /><br />
</ContentTemplate>
</asp:UpdatePanel>
Call from JavaScript: <br />
<input type="text" name="jsString" /><br />
<input type="button" name="jsSubmit" value="Submit" onclick="DisplayName()" />
</form>
Server Intellect offers Windows Hosting Dedicated Servers at affordable prices. I'm very pleased!
Notice again we have an onclick handler, but this time, we are calling a JavaScript function instead of a code-behind method. We will include the following JavaScript at the bottom of the page:

<script language="javascript" type="text/javascript">
function DisplayName() {
Service1.HelloJS(document.getElementById('jsString').value, onSuccess);
}

function onSuccess(string) {
alert(string);
}
</script>
The function we call from the button click, DisplayName, in turn calls a Service method. Because the ScriptManager has the Service Reference, the Service methods are exposed to page level. We also pass the onSuccess function to display the return string in a JavaScript alert box.
Finally, let's move back to the Service1.cs to add our second method, which is being called by JavaScript. It will be just the same as the last one, except not a static method:

[OperationContract]
public String HelloJS(String theString)
{
return "Hello, " + theString + ".";
}
We are using Server Intellect and have found that by far, they are the most friendly, responsive, and knowledgeable support team we've ever dealt with!
Our entire Service1.cs will look something like this:

using System;
using System.Linq;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.ServiceModel.Activation;
using System.ServiceModel.Web;

[ServiceContract(Namespace = "")]
[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Allowed)]
public class Service1
{
// Add [WebGet] attribute to use HTTP GET
[OperationContract]
public void DoWork()
{
// Add your operation implementation here
return;
}

// Add more operations here and mark them with [OperationContract]
[OperationContract]
public static String Hello(String theString)
{
return "Hello, " + theString + ".";
}

[OperationContract]
public String HelloJS(String theString)
{
return "Hello, " + theString + ".";
}
}

Wednesday, 1 February 2012

All Validation Control in Asp.Net and message are show in Validation summery

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

<!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>
   
    </div>
    &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="*"
        style="z-index: 1; left: 13px; top: 53px; position: absolute; width: 5px"
        ForeColor="DarkCyan"></asp:RequiredFieldValidator>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <br />
    <br />
    <asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server"
        ControlToValidate="TextBox1" ErrorMessage="*"
         ForeColor="Red"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server"
        ControlToValidate="TextBox2" ErrorMessage="*" ForeColor="Blue"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator4" runat="server"
        ControlToValidate="TextBox3" ErrorMessage="*" ForeColor="Aqua"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator5" runat="server"
        ControlToValidate="TextBox4" ErrorMessage="*" ForeColor="Brown"></asp:RequiredFieldValidator>
    <br />
     <asp:RequiredFieldValidator ID="RequiredFieldValidator6" runat="server"
        ControlToValidate="TextBox5" ErrorMessage="*"  ForeColor="AliceBlue"></asp:RequiredFieldValidator>
    <br />
    <asp:RegularExpressionValidator ID="RegularExpressionValidator1" runat="server"
        ControlToValidate="TextBox4" ErrorMessage="Enter Valid emailID"
        SetFocusOnError="True"
        style="z-index: 1; left: 21px; top: 112px; position: absolute; right: 1106px"
        ValidationExpression="\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*"
        ForeColor="Red"></asp:RegularExpressionValidator>
    <asp:RangeValidator ID="RangeValidator1" runat="server"
        ControlToValidate="TextBox2"
        ErrorMessage="Range should be between 100 to 20000" MaximumValue="20000"
        MinimumValue="100"
        style="z-index: 1; left: 8px; top: 68px; position: absolute"
        ForeColor="Red" Type="Integer"></asp:RangeValidator>
    <br />
    <asp:TextBox ID="TextBox4" runat="server"
        style="z-index: 1; left: 230px; top: 106px; position: absolute"></asp:TextBox>
    <br />
    <asp:TextBox ID="TextBox3" runat="server"
        style="z-index: 1; left: 233px; top: 148px; position: absolute"></asp:TextBox>
    <br />
    <br />
    <br />
    <br />
    <br />
    <asp:TextBox ID="TextBox5" runat="server"
        style="z-index: 1; left: 232px; top: 183px; position: absolute"></asp:TextBox>
    <asp:Button ID="Button1" runat="server"
        style="z-index: 1; left: 259px; top: 222px; position: absolute" Text="Check" />
    <asp:ValidationSummary ID="ValidationSummary1" runat="server"
        ShowMessageBox="True"
       
        style="z-index: 1; left: 19px; top: 274px; position: absolute; height: 38px; width: 1275px"
        ShowSummary="False" />
    <br />
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
    <asp:TextBox ID="TextBox1" runat="server"
        style="z-index: 1; left: 231px; top: 40px; position: absolute"></asp:TextBox>
    <asp:TextBox ID="TextBox2" runat="server"
        style="z-index: 1; left: 229px; top: 73px; position: absolute"></asp:TextBox>
    <asp:CompareValidator ID="CompareValidator1" runat="server"
        ControlToCompare="TextBox3" ControlToValidate="TextBox5"
        ErrorMessage="Name should be same"
        style="z-index: 1; left: 26px; top: 152px; position: absolute"
        ForeColor="Red"></asp:CompareValidator>
    </form>
</body>
</html>

Desgin Page



RunTime Design



C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

    }
}



Transaction Example.[How user can pay money one account to another account]

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

<!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>
   
        FROM<asp:Label ID="Label3" runat="server"
            style="z-index: 1; left: 5px; top: 81px; position: absolute"
            Text="Amount"></asp:Label>
   
        <asp:DropDownList ID="drpfrom" runat="server" AutoPostBack="True"
            onselectedindexchanged="drpfrom_SelectedIndexChanged">
        </asp:DropDownList>
   
        <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
   
    </div>
    <asp:TextBox ID="txtamount" runat="server"
        style="z-index: 1; left: 58px; top: 84px; position: absolute"></asp:TextBox>
    <asp:Button ID="btnsave" runat="server"
        style="z-index: 1; left: 199px; top: 79px; position: absolute"
        Text="Save" onclick="btnsave_Click" />
    <asp:DropDownList ID="drpto" runat="server"
        style="position:absolute; top: 43px; left: 57px;" AutoPostBack="True"
        onselectedindexchanged="drpto_SelectedIndexChanged">
    </asp:DropDownList>
    <asp:Label ID="To" runat="server"
            style="z-index: 1; left: 8px; top: 45px; position: absolute"
        Text="To A/c"></asp:Label>
    <asp:TextBox ID="TextBox2" runat="server"
        style="position:absolute; top: 40px; left: 135px;"></asp:TextBox>
    <p>
  
    </p>
    <asp:GridView ID="GridView1" runat="server"
        style="position:absolute; top: 199px; left: 196px;">
    </asp:GridView>
    <p>
        &nbsp;</p>
    <p>
    <asp:Label ID="Label4" runat="server" Text="Label"
            style="position:absolute; top: 158px; left: 67px;"></asp:Label>
    </p>
    </form>
</body>
</html>
Design Example



Runtime Design
 
 
C# Coading
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;
using System.Data.SqlClient;


public partial class Transction : System.Web.UI.Page
{
    SqlConnection con = new SqlConnection("server=Satya\\S12;database=linku;uid=li;pwd=4555");
    SqlDataAdapter da;
    DataTable dt;
    Class1 obj = new Class1();
    protected void Page_Load(object sender, EventArgs e)
    {
        con.Open();
        Label4.Visible = false;
        if(!Page.IsPostBack)
        {
            FillDrp();
            fillGrid();
        }
    }
    protected void btnsave_Click(object sender, EventArgs e)
    {
        obj = new Class1();
        Hashtable ht = new Hashtable();
        ht.Add("FromAcno", drpfrom.SelectedValue);
        ht.Add("Toacno ", drpto.SelectedValue);
        ht.Add("amount", txtamount.Text);
     
       obj.ExecuteQuery("TrDemo1", ht);
       Label4.Visible = true;
       Label4.Text="success";
       fillGrid();
     
    }
    public void FillDrp()
    {
        da = new SqlDataAdapter("Select * from Fromac", con);
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        dt = new DataTable();
        da.Fill(dt);
        drpfrom.DataSource = dt;
        drpto.DataSource = dt;
        drpfrom.DataTextField = "FromAcno";
        drpfrom.DataValueField = "FromAcno";
        drpfrom.DataBind();
        drpto.DataTextField = "FromAcno";
        drpto.DataValueField = "FromAcno";
        drpto.DataBind();
    }
    public void fillGrid()
    {
        da = new SqlDataAdapter("Select * from Fromac", con);
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        dt = new DataTable();
        da.Fill(dt);
        GridView1.DataSource = dt;
        GridView1.DataBind();

    }
    public void FillNamebyACNO()
    {
        da = new SqlDataAdapter("Select Name from Fromac where FromAcno='"+drpfrom.SelectedValue+"'", con);
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        dt = new DataTable();
        da.Fill(dt);
        TextBox1.Text = dt.Rows[0]["Name"].ToString();
        //TextBox2.Text = dt.Rows[0]["Name"].ToString();
    }
    public void FillNametoACNO()
    {
        da = new SqlDataAdapter("Select Name from Fromac where FromAcno='" + drpto.SelectedValue + "'", con);
        if (con.State == ConnectionState.Open)
        {
            con.Close();
        }
        con.Open();
        dt = new DataTable();
        da.Fill(dt);
      
        TextBox2.Text = dt.Rows[0]["Name"].ToString();
    }
    protected void drpfrom_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillNamebyACNO();

    }
    protected void drpto_SelectedIndexChanged(object sender, EventArgs e)
    {
        FillNametoACNO();
    }
}

Class File Coadiong
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Collections;

/// <summary>
/// Summary description for Class1
/// </summary>
public class Class1
{
    private SqlConnection con;
    public Class1()
    {
        con = new SqlConnection(@"server=Satya/aa;database=linku;uid=li;pwd=li123");
    }
    public void ExecuteQuery(string sp,Hashtable ht)
    {
        try
        {
            if (con.State == ConnectionState.Open)
            {
                con.Close();
            }
            con.Open();
            SqlCommand cmd = new SqlCommand(sp, con);
            cmd.CommandType = CommandType.StoredProcedure;
            foreach (DictionaryEntry p in ht)
            {
                cmd.Parameters.Add("@" + (string)p.Key, p.Value);
            }
            cmd.ExecuteNonQuery();
            con.Close();
            cmd.Dispose();
        }
        catch (Exception ex)
        {
            string errMsg = ex.Message;
        }
        finally
        {

            if (this.con.State == ConnectionState.Open)
                con.Close();
            if (this.con != null) this.con = null;
            if (this.con != null) this.con = null;
        }
    }
}
 Storeprocedure

Create procedure TrDemo1
(
@FromAcno int,

@amount decimal(18,2),
@Toacno int
)
as
BEGIN
BEGIN TRY
BEGIN TRANSACTION
Update Fromac set amount=(amount-@amount) where FromAcno=@FromAcno
Update Fromac set amount=(amount+@amount) where FromAcno=@Toacno
print 'success'
COMMIT TRANSACTION
END TRY
BEGIN CATCH
ROLLBACK TRANSACTION
PRINT 'ERROR'
END CATCH
END
Database Table