.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="same.aspx.cs" Inherits="same" %>
.aspx.cs
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.Configuration;
using System.Data.SqlClient;
public partial class same : System.Web.UI.Page
{
SqlCommand cmd = null;
SqlConnection cn = null;
SqlDataAdapter da = null;
DataSet ds = null;
protected void Page_Load(object sender, EventArgs e)
{
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString);
if(!Page.IsPostBack)
{
BindCountry();
}
BindGrid();
}
public void BindCountry()
{
cmd = new SqlCommand("findcountry", cn);
cmd.CommandType = CommandType.StoredProcedure;
ds = new DataSet();
da = new SqlDataAdapter(cmd);
da.Fill(ds);
ddlcountry.DataSource = ds;
ddlcountry.DataTextField = "cname";
ddlcountry.DataValueField = "ccid";
ddlcountry.DataBind();
}
public void BindState()
{
cmd = new SqlCommand("findstate", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@ccid", SqlDbType.Int).Value = ddlcountry.SelectedValue;
da = new SqlDataAdapter(cmd);
ds=new DataSet();
da.Fill(ds);
ddlstate.DataSource = ds;
ddlstate.DataTextField = "sname";
ddlstate.DataValueField = "sid";
ddlstate.DataBind();
}
public void BindCity()
{
cmd = new SqlCommand("findcity", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@sid", SqlDbType.Int).Value = ddlstate.SelectedValue;
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
ddlcity.DataSource = ds;
ddlcity.DataTextField = "cname";
ddlcity.DataValueField = "cid";
ddlcity.DataBind();
}
protected void btnsave_Click(object sender, EventArgs e)
{
cn.Open();
cmd = new SqlCommand("insertorupdate", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@eid", (hfid.Value == "" ? 0 : Convert.ToInt32(hfid.Value)));
cmd.Parameters.AddWithValue("@fname", txtfname.Text.Trim());
cmd.Parameters.AddWithValue("@lname", txtlname.Text.Trim());
cmd.Parameters.AddWithValue("@designation", txtdesignation.Text.Trim());
cmd.Parameters.AddWithValue("@salary", txtsal.Text.Trim());
cmd.Parameters.AddWithValue("@dob", txtdob.Text.Trim());
string Gender = null;
if(rbmael.Checked)
{
Gender="Male";
}
else
{
Gender="Female";
}
cmd.Parameters.AddWithValue("@gender", Gender);
cmd.Parameters.AddWithValue("@cid",ddlcity.SelectedItem.Value);
cmd.ExecuteNonQuery();
if(hfid.Value=="")
{
lblsuccess.Text = "Save Successfully";
}
else
{
lblsuccess.Text = "Update Successfully";
}
Clear();
BindGrid();
}
protected void btnClear_Click(object sender, EventArgs e)
{
Clear();
}
public void Clear()
{
hfid.Value = "";
txtlname.Text = txtfname.Text = txtsal.Text = txtdob.Text = txtdesignation.Text = string.Empty;
}
protected void ddlstate_SelectedIndexChanged(object sender, EventArgs e)
{
BindCity();
}
protected void ddlcountry_SelectedIndexChanged(object sender, EventArgs e)
{
BindState();
}
protected void lbledit_Click(object sender, EventArgs e)
{
int eid = Convert.ToInt32((sender as LinkButton).CommandArgument);
cn.Open();
da = new SqlDataAdapter("viewalldataid", cn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("@eid", eid);
DataTable dt = new DataTable();
da.Fill(dt);
cn.Close();
hfid.Value = eid.ToString();
txtfname.Text = dt.Rows[0]["fname"].ToString();
txtlname.Text = dt.Rows[0]["lname"].ToString();
txtdesignation.Text = dt.Rows[0]["designation"].ToString();
txtdob.Text = dt.Rows[0]["dob"].ToString();
txtsal.Text = dt.Rows[0]["salary"].ToString();
btnsave.Text = "Update";
}
public void BindGrid()
{
cmd = new SqlCommand("viewalldata", cn);
cmd.CommandType = CommandType.StoredProcedure;
da = new SqlDataAdapter(cmd);
ds = new DataSet();
da.Fill(ds);
gd1.DataSource = ds;
gd1.DataBind();
}
protected void lbldelete_Click(object sender, EventArgs e)
{
cn.Open();
cmd = new SqlCommand("deleterecord", cn);
cmd.CommandType=CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@eid", Convert.ToInt32(hfid.Value));
cmd.ExecuteNonQuery();
cn.Close();
Clear();
}
}
Diifernt pages
same .aspx
.aspx.cs
protected void lbkedit_Click(object sender, EventArgs e)
{
int eid = Convert.ToInt32((sender as LinkButton).CommandArgument);
Session["session_emp"] = eid;
Response.Redirect("diff1.aspx");
}
second page design is same only coding is diifferent
protected void Page_Load(object sender, EventArgs e)
{
cn = new SqlConnection(ConfigurationManager.ConnectionStrings["SqlCon"].ConnectionString);
if(!Page.IsPostBack)
{
bindcountry();
}
cn.Open();
da = new SqlDataAdapter("viewalldataid", cn);
da.SelectCommand.CommandType = CommandType.StoredProcedure;
da.SelectCommand.Parameters.AddWithValue("@eid", Session["session_emp"]);
DataTable dt = new DataTable();
da.Fill(dt);
cn.Close();
hfid.Value = Session["session_emp"].ToString();
txtfname.Text = dt.Rows[0]["fname"].ToString();
txtlname.Text = dt.Rows[0]["lname"].ToString();
txtdesign.Text = dt.Rows[0]["designation"].ToString();
txtsal.Text = dt.Rows[0]["salary"].ToString();
txtdob.Text = dt.Rows[0]["dob"].ToString();
}
protected void btnupdate_Click(object sender, EventArgs e)
{
cn.Open();
cmd = new SqlCommand("insertorupdate", cn);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.AddWithValue("@eid",(hfid.Value==""?0:Convert.ToInt32(hfid.Value)));
cmd.Parameters.AddWithValue("@fname",txtfname.Text.Trim());
cmd.Parameters.AddWithValue("@lname",txtlname.Text.Trim());
cmd.Parameters.AddWithValue("@designation",txtdesign.Text.Trim());
cmd.Parameters.AddWithValue("@salary",txtsal.Text.Trim());
cmd.Parameters.AddWithValue("@dob",txtdob.Text.Trim());
cmd.Parameters.AddWithValue("@cid", ddlcity.SelectedItem.Value);
lblsuccess.Text="Update Successfully....";
}
Stord Procedures
i
Nitin SontakkePosted Mar 22, 2018, 10:25 PM