Monday, 12 November 2012

Simple Page Coding Cs.Page

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

<!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%;
        }
        .style2
        {
            width: 239px;
        }
        .style3
        {
            width: 187px;
        }
    </style>
</head>
<body>
    <form id="form1" runat="server">
    <div>
  
        <table class="style1">
            <tr>
                <td class="style2">
                    Title</td>
                <td class="style3">
                    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
                </td>
                <td>
                    <br />
                    <br />
                </td>
            </tr>
            <tr>
                <td class="style2">
                    Firstname
                </td>
                <td class="style3">
                    <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    Middlename</td>
                <td class="style3">
                    <asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    <asp:Button ID="Button1" runat="server" onclick="Button1_Click" Text="Save" />
                </td>
                <td class="style3">
                    <asp:Button ID="Button2" runat="server"
                        Text="Modified" onclick="Button2_Click" />
                    <asp:Button ID="Button3" runat="server" Text="Deleted"
                        onclick="Button3_Click" />
                    <asp:Button ID="Button4" runat="server" Text="Cancel" />
                </td>
                <td>
                    &nbsp;</td>
            </tr>
            <tr>
                <td class="style2">
                    &nbsp;</td>
                <td class="style3">
                    <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns =false
                        CellPadding="4" ForeColor="#333333"
                        GridLines="None" Height="90px"
                     Width="332px" >
                        <AlternatingRowStyle BackColor="White" />
                        <FooterStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <HeaderStyle BackColor="#990000" Font-Bold="True" ForeColor="White" />
                        <PagerStyle BackColor="#FFCC66" ForeColor="#333333" HorizontalAlign="Center" />
                        <RowStyle BackColor="#FFFBD6" ForeColor="#333333" />
                        <SelectedRowStyle BackColor="#FFCC66" Font-Bold="True" ForeColor="Navy" />
                        <SortedAscendingCellStyle BackColor="#FDF5AC" />
                        <SortedAscendingHeaderStyle BackColor="#4D0000" />
                        <SortedDescendingCellStyle BackColor="#FCF6C0" />
                        <SortedDescendingHeaderStyle BackColor="#820000" />
                         <Columns>
                          <asp:BoundField  DataField="Id" HeaderText="Id"/>
                          <asp:BoundField  DataField="Title" HeaderText="Title"/>
                          <%--<asp:BoundField  DataField="Firstname" HeaderText="Firstname"/>--%>
                          <asp:BoundField  DataField="MiddleName" HeaderText="MiddleName"/>
                          <asp:HyperLinkField DataNavigateUrlFields="ID" DataNavigateUrlFormatString="Empmaster.aspx?id={0}"
                                    DataTextField="Firstname" HeaderText="First name" />
                          </Columns>

                    </asp:GridView>
                </td>
                <td>
                    &nbsp;</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;
using System.Data;
using System.Data.SqlClient;



public partial class Empmaster : System.Web.UI.Page
{
    public int id;
    Runtype run = new Runtype();

   protected void Page_Load(object sender, EventArgs e)
    {
       
    
        if (!Page.IsPostBack)
        {
            GetDataItem();
            id = Convert.ToInt32(Page.Request.QueryString["id"]);


            if (id > 0)
            {
                DataSet Ds = new DataSet();
                Ds = run.GetDataByRecid(id);
                TextBox1.Text = Ds.Tables[0].Rows[0]["Title"].ToString();
                TextBox2.Text = Ds.Tables[0].Rows[0]["Firstname"].ToString();
                TextBox3.Text = Ds.Tables[0].Rows[0]["MiddleName"].ToString();
            }

          
        }



    }
   public void GetDataItem()
   {
      try
       {
           DataSet ds = new DataSet();
           ds = run.GetData();
           GridView1.DataSource = ds;
           GridView1 .DataBind();



       }
       catch (Exception ex)
       {



       }
   }
    protected void Button1_Click(object sender, EventArgs e)
    {
        putdata();
        Savedata(run.dtrip);
    }


    public void putdata()
    {
        run.intitable();
        run.dtrip.Rows[0]["Title"]=TextBox1.Text;
        run.dtrip.Rows[0]["Firstname"] = TextBox2.Text;
        run.dtrip.Rows[0]["Middlename"] = TextBox3.Text;
    }

      public void Savedata(DataTable dt )
    {
        DataSet Ds = new DataSet();
        Ds.Tables.Add(dt);
        run.SaveRecords(Ds);
    }


      protected void Button2_Click(object sender, EventArgs e)
      {
          id = Convert.ToInt16(Page.Request.QueryString["id"]);
          if (id > 0)
          {
              putdata();
              Updatedata(run.dtrip,id);
              GetDataItem();
          }
 
        

      }

      public void Updatedata(DataTable dt, int id11)
      {
          DataSet Ds = new DataSet();
          Ds.Tables.Add(dt);
          run.UpdateRecords(Ds, id11);
      }

      protected void Button3_Click(object sender, EventArgs e)
      {
          id = Convert.ToInt16(Page.Request.QueryString["id"]);
         long iwq;
          iwq = run.DeleteRecords(id);
          if (iwq == 2)


          {
              ScriptManager.RegisterStartupScript(this, this.GetType(), "Success", "alert('Your Records should be deleted !');", true);
              GetDataItem();


          }




      }
}

No comments:

Post a Comment