GridView Code in asp.net :
GRID
VIEW CONTROLER CODE:using N tire architecher
Using
strored procedure:
Default.aspx
page 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;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{ getdata(); }
}
balusers obj=new balusers();
public void getdata()
{
DataSet myds = obj.getempdata();
GridView1.DataSource = myds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
getdata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox t1, t2, t3;
t1 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt1");
t2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt2");
t3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt3");
obj.Eno = int.Parse(t1.Text);
obj.Ename = t2.Text;
obj.Sal = int.Parse(t3.Text);
obj.update();
getdata();
}
public void insert(object sender, EventArgs e)
{ TextBox t1, t2, t3;
t1 = (TextBox)GridView1.FooterRow.FindControl("ft1");
t2 = (TextBox)GridView1.FooterRow.FindControl("ft2");
t3 = (TextBox)GridView1.FooterRow.FindControl("ft3");
obj.Eno = int.Parse(t1.Text);
obj.Ename = t2.Text;
obj.Sal = int.Parse(t3.Text);
obj.insertdata();
getdata();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label l = (Label)GridView1.Rows[e.RowIndex].FindControl("ll");
SqlConnection cn = new SqlConnection("uid=sa;database=guru;password=123;server=GOPI");
cn.Open();
SqlCommand cmd = new SqlCommand("delete from emp5
where eno="+l.Text+"",cn);
cmd.ExecuteNonQuery();
getdata();
}
}
THIS SOURCE
CODE:
</head>
<body>
<form id="form1" runat="server">
<div>
</div>
<table class="auto-style1">
<tr>
<td><asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:UpdatePanel ID="UpdatePanel1" runat="server">
<ContentTemplate>
<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" ShowFooter="True">
<Columns>
<asp:TemplateField HeaderText="Eno">
<ItemTemplate>
<asp:Label ID="ll" runat="server" BackColor="Yellow" Text='<%#Eval("eno") %>'></asp:Label>
<%#Eval("eno") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt1" runat="server" Text='<%#Eval("eno") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft1" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Ename">
<ItemTemplate>
<%#Eval("ename") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt2" runat="server" Text='<%#Eval("ename") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft2" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Salary">
<ItemTemplate>
<%#Eval("sal") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt3" runat="server" Text='<%#Eval("sal") %>'></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft3" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField>
<FooterTemplate>
<asp:Button ID="bt" runat="server" BackColor="Yellow" OnCommand="insert" Text="SAVE" />
</FooterTemplate>
</asp:TemplateField>
<asp:CommandField ShowEditButton="true" />
<asp:CommandField ShowDeleteButton="true" />
</Columns>
</asp:GridView>
DALUSERS
CODE CLASS FILE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Web.Configuration;
/// <summary>
/// Summary description for daluser
/// </summary>
public class daluser
{
public static DataSet getrecords(string connec, string proced)
{
try
{
SqlConnection cn = new SqlConnection(connec);
SqlDataAdapter da = new SqlDataAdapter(proced, cn);
DataSet ds = new DataSet();
da.Fill(ds);
return ds;
}
catch (Exception ex)
}
public static void getmanupulations(string conn, string pro, SqlParameter[] p)
{
try
{
SqlConnection cn = new SqlConnection(conn);
cn.Open();
SqlCommand cmd = new SqlCommand(pro, cn);
cmd.CommandType = CommandType.StoredProcedure;
foreach (SqlParameter param in p)
{
cmd.Parameters.Add(param);
}
cmd.ExecuteNonQuery();
}
catch (Exception ex)
{ throw new ArgumentException(ex.Message); }
}
}
BALUSERS
CLASS FILE CODE:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Configuration;
using System.Data.SqlClient;
using System.Data;
/// <summary>
/// Summary description for balusers
/// </summary>
public class balusers
{
int eno, sal;
string ename;
public int Sal
{
get { return sal; }
set { sal = value; }
}
public int Eno
{
get { return eno; }
set { eno = value; }
}
public string Ename
{
get { return ename; }
set { ename = value; }
}
public void insertdata()
{
try
{
SqlParameter[] p = new SqlParameter[3];
p[0] = new SqlParameter("@eno", eno);
p[0].DbType = DbType.Int32;
p[1] = new SqlParameter("@ename",
ename);
p[1].DbType = DbType.String;
p[2] = new SqlParameter("@sal", sal);
p[2].DbType = DbType.Int32;
daluser.getmanupulations(WebConfigurationManager.AppSettings["conn"], "spinsert6", p);
}
catch (Exception ex)
{ throw new ArgumentException(ex.Message); }
}
public void update()
{
SqlParameter[] p = new SqlParameter[3];
p[0] = new SqlParameter("@eno", eno);
p[0].DbType = DbType.Int32;
p[1] = new SqlParameter("@ename",
ename);
p[1].DbType = DbType.String;
p[2] = new SqlParameter("@sal", sal);
p[2].DbType = DbType.Int32;
daluser.getmanupulations(WebConfigurationManager.AppSettings["conn"],"spupdate6",p);
}
public DataSet getempdata()
{ DataSet ds = daluser.getrecords(WebConfigurationManager.AppSettings["conn"], "spgetdata5");
return ds;
}
}
OUTPUT
SCREEN SHOT:
This is wizard and gridview code
This is wizard and gridview 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;
using System.Data.SqlClient;
using System.Web.Configuration;
public partial class wizard1 : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
getdata();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection(WebConfigurationManager.AppSettings["conn"]);
cn.Open();
SqlCommand CMD = new SqlCommand("insert reg
values('" + TextBox1.Text + "','" +
TextBox2.Text + "','" + TextBox3.Text + "','" + TextBox4.Text + "','"+TextBox5.Text + "','" + TextBox6.Text + "','" + TextBox7.Text + "','" + TextBox8.Text + "','" + TextBox9.Text + "','" + TextBox10.Text + "')", cn);
CMD.ExecuteNonQuery();
Label1.Text = "Record added sucessfully..";
}
protected void Button4_Click(object sender, EventArgs e)
{
SqlConnection cn = new SqlConnection("uid=sa;password=123;database=guru;server=GURU-PC");
cn.Open();
SqlCommand CMD = new SqlCommand("update reg set
faname='" + TextBox2.Text + "',dob='" +
TextBox3.Text + "',gend='" + TextBox4.Text + "',adr='" + TextBox5.Text + "',mbno='" + TextBox6.Text + "',grad='" + TextBox7.Text + "',email='" + TextBox8.Text + "',nat='" + TextBox9.Text + "',rel='" + TextBox10.Text + "'
where fname='" + TextBox1.Text + "'", cn);
CMD.ExecuteNonQuery();
Label1.Text="Record
updated sucessfully..";
}
void getdata()
{
SqlConnection cn = new SqlConnection(WebConfigurationManager.AppSettings["conn"]);
SqlDataAdapter da = new SqlDataAdapter("select*from reg", cn);
DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds.Tables[0];
GridView1.DataBind();
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
getdata();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
TextBox t1, t2, t3,t4,t5,t6,t7,t8,t9,t10;
t1=(TextBox)GridView1.Rows[e.RowIndex].FindControl("tt1");
t2 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt2");
t3 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt3");
t4 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt4");
t5 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt5");
t6 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt6");
t7 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt7");
t8= (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt8");
t9= (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt9");
t10 = (TextBox)GridView1.Rows[e.RowIndex].FindControl("tt10");
SqlConnection cn = new SqlConnection(WebConfigurationManager.AppSettings["conn"]);
cn.Open();
SqlCommand CMD = new SqlCommand("update reg set
faname='" + t2.Text + "',dob='" +
t3.Text + "',gend='" + t4.Text + "',adr='" + t5.Text + "',mbno='" + t6.Text + "',grad='" + t7.Text + "',email='" + t8.Text + "',nat='" + t9.Text + "',rel='" + t10.Text + "'
where fname='" + t1.Text + "'", cn);
CMD.ExecuteNonQuery();
getdata();
}
protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
{
Label l= (Label)GridView1.Rows[e.RowIndex].FindControl("l1");
SqlConnection cn = new SqlConnection(WebConfigurationManager.AppSettings["conn"]);
cn.Open();
SqlCommand CMD = new SqlCommand("delete from reg where fname='"+l.Text+"'",cn);
CMD.ExecuteNonQuery();
getdata();
}
protected void bt_Command(object sender, CommandEventArgs e)
{
TextBox t1, t2, t3, t4, t5, t6, t7, t8, t9, t10;
t1 = (TextBox)GridView1.FooterRow.FindControl("ft1");
t2 = (TextBox)GridView1.FooterRow.FindControl("ft2");
t3 = (TextBox)GridView1.FooterRow.FindControl("ft3");
t4 = (TextBox)GridView1.FooterRow.FindControl("ft4");
t5 = (TextBox)GridView1.FooterRow.FindControl("ft5");
t6 = (TextBox)GridView1.FooterRow.FindControl("ft6");
t7 = (TextBox)GridView1.FooterRow.FindControl("ft7");
t8 = (TextBox)GridView1.FooterRow.FindControl("ft8");
t9 = (TextBox)GridView1.FooterRow.FindControl("ft9");
t10 = (TextBox)GridView1.FooterRow.FindControl("ft10");
SqlConnection cn = new SqlConnection(WebConfigurationManager.AppSettings["conn"]);
cn.Open();
SqlCommand CMD = new SqlCommand("insert reg
values('" + t1.Text + "','" +
t2.Text + "','" + t3.Text + "','" + t4.Text + "','" + t5.Text + "','" + t6.Text + "','" + t7.Text + "','" + t8.Text + "','" + t9.Text + "','" + t10.Text + "')", cn);
CMD.ExecuteNonQuery();
getdata();
}
protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
Response.Redirect("wizard1.aspx");
}
}
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="wizard1.aspx.cs" Inherits="wizard1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<style type="text/css">
.auto-style1 {
width: 91%;
height: 21px;
}
.auto-style2 {
height: 23px;
}
</style>
</head>
<body>
<form id="form1" runat="server" style="background-repeat: no-repeat; background-color: #00FFFF; height: 894px; width: 1750px; background-image: url('images/images (1).jpg');">
<div>
</div>
<asp:Wizard ID="Wizard2" runat="server" DisplayCancelButton="True" Height="517px" Width="1076px" ActiveStepIndex="1" CancelDestinationPageUrl="~/wizard1.aspx" >
<WizardSteps>
<asp:WizardStep runat="server" title="Registrationform">
<table class="auto-style1">
<tr>
<td>FullName:</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Father Name:</td>
<td>
<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Date of Birth:</td>
<td>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Gender:</td>
<td>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td>Address:</td>
<td>
<asp:TextBox ID="TextBox5" runat="server" Height="45px" Width="123px" TextMode="MultiLine"></asp:TextBox>
</td>
</tr>
<tr>
<td>MobileNo:</td>
<td>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Graduation:</td>
<td class="auto-style2">
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">EmailId:</td>
<td class="auto-style2">
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Nationality:</td>
<td class="auto-style2">
<asp:TextBox ID="TextBox9" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">Religion:</td>
<td class="auto-style2">
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
</td>
</tr>
<tr>
<td class="auto-style2">
<asp:Button ID="Button4" runat="server" OnClick="Button4_Click" Text="Edit" />
</td>
<td class="auto-style2">
<asp:Button ID="Button1" runat="server" Text="Save" OnClick="Button1_Click" />
</td>
</tr>
<tr>
<td class="auto-style2" colspan="2">
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label>
</td>
</tr>
</table>
</asp:WizardStep>
<asp:WizardStep ID="WizardStep1" runat="server" title="Total Data">
<br />
<br />
<asp:GridView ID="GridView1" runat="server" Height="16px" Width="6px" CellPadding="4" ForeColor="#333333" GridLines="None" AutoGenerateColumns="False" ShowFooter="True" OnRowDeleting="GridView1_RowDeleting" OnRowEditing="GridView1_RowEditing" OnRowUpdating="GridView1_RowUpdating" OnRowCancelingEdit="GridView1_RowCancelingEdit" ViewStateMode="Enabled" style="position: relative; top: -114px; left: -21px; margin-top: 115px">
<AlternatingRowStyle BackColor="White" />
<EditRowStyle BackColor="#2461BF" />
<FooterStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<HeaderStyle BackColor="#507CD1" Font-Bold="True" ForeColor="White" />
<PagerStyle BackColor="#2461BF" ForeColor="White" HorizontalAlign="Center" />
<RowStyle BackColor="#EFF3FB" />
<SelectedRowStyle BackColor="#D1DDF1" Font-Bold="True" ForeColor="#333333" HorizontalAlign="Left" VerticalAlign="Middle" />
<SortedAscendingCellStyle BackColor="#F5F7FB" />
<SortedAscendingHeaderStyle BackColor="#6D95E1" />
<SortedDescendingCellStyle BackColor="#E9EBEF" />
<SortedDescendingHeaderStyle BackColor="#4870BE" />
<Columns>
<asp:TemplateField HeaderText="Fullname">
<ItemTemplate><asp:Label ID="l1" Text='<%#Eval("fname") %>' runat="server" BackColor="Yellow"></asp:Label>
<%#Eval("fname") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt1" Text='<%#Eval("fname") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft1" runat="server"></asp:TextBox>
</FooterTemplate>
<ItemStyle BackColor="White" />
</asp:TemplateField>
<asp:TemplateField HeaderText="Father">
<ItemTemplate>
<%#Eval("faname") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt2" Text='<%#Eval("faname") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft2" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="DOB">
<ItemTemplate>
<%#Eval("dob") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt3" Text='<%#Eval("dob") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft3" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GENDER">
<ItemTemplate>
<%#Eval("gend") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt4" Text='<%#Eval("gend") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft4" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Address">
<ItemTemplate>
<%#Eval("adr") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt5" Text='<%#Eval("adr") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft5" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Mobile">
<ItemTemplate>
<%#Eval("mbno") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt6" Text='<%#Eval("mbno") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft6" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="GRADUATION">
<ItemTemplate>
<%#Eval("grad") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt7" Text='<%#Eval("grad") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft7" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Email">
<ItemTemplate>
<%#Eval("email") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt8" Text='<%#Eval("email") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft8" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="NATIONALITY">
<ItemTemplate>
<%#Eval("nat") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt9" Text='<%#Eval("nat") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft9" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField HeaderText="Religion">
<ItemTemplate>
<%#Eval("rel") %>
</ItemTemplate>
<EditItemTemplate>
<asp:TextBox ID="tt10" Text='<%#Eval("rel") %>' runat="server"></asp:TextBox>
</EditItemTemplate>
<FooterTemplate>
<asp:TextBox ID="ft10" runat="server"></asp:TextBox>
</FooterTemplate>
</asp:TemplateField>
<asp:TemplateField><FooterTemplate>
<asp:Button ID="bt" Text="save" OnCommand="bt_Command" runat="server" BackColor="Yellow" />
</FooterTemplate></asp:TemplateField>
<asp:CommandField ShowEditButton="true" >
<ControlStyle BackColor="#00FF99" BorderColor="#00CC00" />
</asp:CommandField>
<asp:CommandField ShowDeleteButton="true" />
</Columns>
</asp:GridView>
</asp:WizardStep>
</WizardSteps>
</asp:Wizard>
</form>
</body>
</html>
0 Comments