////////////////////////////////////////////////////
//////////////////////MY TABLE//////////////////
////////////////////////////////////////////////////
USE [logistics_tab]
GO
/****** Object: Table [dbo].[dtype] Script Date: 02/07/2015 10:19:00 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[dtype](
[dtid] [int] IDENTITY(1,1) NOT NULL,
[dtcd] [char](5) NOT NULL,
[desp] [char](15) NOT NULL,
CONSTRAINT [PK_dtype] PRIMARY KEY CLUSTERED
(
[dtid] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
CONSTRAINT [Uq_dtcd_Dtype] UNIQUE NONCLUSTERED
(
[dtcd] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
////////////////////////////////////////////////////
////////////MY STORED PROCEDURE/////////////////////
////////////////////////////////////////////////////
USE [logistics_tab]
GO
/****** Object: StoredProcedure [dbo].[dtype_pro] Script Date: 02/07/2015 10:21:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE PROCEDURE [dbo].[dtype_pro]
(
@dtid as int=0,
@dtcd as char(5)='',
@desp as char(15)='',
@status as varchar(50)=''
)
AS
BEGIN
SET NOCOUNT ON;
if(@status = 'Display')
begin
Select * from dtype
end
else if(@status = 'Add')
begin
Insert into dtype(dtcd,desp) values (@dtcd,@desp)
end
else if(@status = 'Update')
begin
Update dtype set dtcd=@dtcd, desp=@desp where dtid=@dtid
end
else if(@status = 'Delete')
begin
Delete from dtype where dtid=@dtid
end
END
GO
////////////////////////////////////////////////////
//////////MY DESIGN PAGE/////////////
////////////////////////////////////////////////////
<%@ Page Title="" Language="C#" MasterPageFile="~/Site.Master" AutoEventWireup="true" CodeBehind="DestnType.aspx.cs" Inherits="LogisticsApp.DestnType" %>
<asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
<asp:FormView ID="FormView1" runat="server" DataKeyNames= "dtid" GridLines="Both"
AllowPaging="True" PagerStyle-BorderStyle="NotSet" PagerStyle-ForeColor="Black">
<FooterStyle BackColor="#CCCCCC" ForeColor="Black" />
<PagerStyle BackColor="#B5C7DE" ForeColor="Black" HorizontalAlign="Center" Font-Bold="true" Font-Size="Large"/>
<ItemTemplate>
<table>
<tr><td align="right"><b>Employee ID:</b></td><td><%# Eval("dtid") %></td></tr>
<tr>
<td colspan="2">
<asp:LinkButton ID="EditButton"
Text="Edit"
CommandName="Edit"
RunAt="server"/>
<asp:LinkButton ID="NewButton"
Text="New"
CommandName="New"
RunAt="server"/>
<asp:LinkButton ID="DeleteButton"
Text="Delete"
CommandName="Delete"
RunAt="server"/>
</td>
</tr>
</table>
</ItemTemplate>
<PagerTemplate>
<table>
<tr>
<td><asp:Button ID="FirstButton1" CommandName="Page" CommandArgument="First"
Text="<1<" RunAt="server" Font-Bold="True" /> </td>
</tr>
</table>
</PagerTemplate>
</asp:FormView>
</asp:Content>
/////////////////////////////////
///////MY CODE///////////
////////////////////////////
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Text.RegularExpressions;
namespace LogisticsApp
{
public partial class DestnType : System.Web.UI.Page
{
public LogisticsApp.MyConnection.OfcConn constr = new MyConnection.OfcConn();
SqlConnection con;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
DataTable dt;//for form view
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
protected void BindGrid()
{
try
{
con = new SqlConnection(constr.str);
dt = new DataTable();//for form view
com = new SqlCommand();
con.Open();
com.Connection = con;
com.CommandText = "dtype_pro";
com.CommandType = CommandType.StoredProcedure;
com.Parameters.Add(new SqlParameter("@status", SqlDbType.VarChar, 50));
com.Parameters["@status"].Value = "Display";
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(dt);//for formview
sqlda.Fill(ds);
if (ds.Tables[0].Rows.Count > 0) //Check if DataTable returns data
{
FormView1.DataSource = dt;
DataBind();
}
}
catch (Exception ex)
{
//lblerr.Text = ex.Message;
throw ex;
}
finally
{
if (con != null)
{
if (con.State == ConnectionState.Open)
con.Close();
con = null;
}
}
}
protected void DtypeFormView_PageIndexChanging(object sender, FormViewPageEventArgs e)
{
FormView1.PageIndex = e.NewPageIndex;
BindGrid();
}
}
}
//plz plz... help as soon as possible this is simple code but not show at run time....... :(