How can i do ??
please tell me some ideas to do such a thing..
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Satyapriya NayakPosted Feb 24, 2013, 12:48 AM
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Gridview_update_other_page._Default" %>
Default.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview_update_other_page
{
public partial class _Default : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
BindGrid();
}
}
protected void BindGrid()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from employee";
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
//com.ExecuteNonQuery();
con.Close();
ds = new DataSet();
sqlda.Fill(ds, "employee");
GridView1.DataSource = ds;
GridView1.DataMember = "employee";
GridView1.DataBind();
}
}
}
Insert.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Insert.aspx.cs" Inherits="Gridview_update_other_page.Insert" %>
Insert.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview_update_other_page
{
public partial class Insert : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
string str;
protected void btn_insert_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "insert into employee(Empname,EmpFname,EmpLname,Empcity,Empstate) values('" + txtFullName.Text + "','" + txtFName.Text + "','" + txtLName.Text + "','" + txtcity.Text + "','" + txtstate.Text + "')";
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
con.Close();
Response.Redirect("Default.aspx");
}
protected void Page_Load(object sender, EventArgs e)
{
}
}
}
Update.aspx
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Update.aspx.cs" Inherits="Gridview_update_other_page.Update" %>
Update.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
namespace Gridview_update_other_page
{
public partial class Update : System.Web.UI.Page
{
string connStr = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
string str;
int empid = 0;
protected void Page_Load(object sender, EventArgs e)
{
empid = Convert.ToInt32(Request.QueryString["Empid"].ToString());
if (!IsPostBack)
{
Bind();
}
}
private void Bind()
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "select * from employee where Empid=" + empid;
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
com.ExecuteNonQuery();
con.Close();
ds = new DataSet();
sqlda.Fill(ds);
lblFullName.Text = ds.Tables[0].Rows[0][1].ToString();
txtFName.Text = ds.Tables[0].Rows[0][2].ToString();
txtLName.Text = ds.Tables[0].Rows[0][3].ToString();
txtcity.Text = ds.Tables[0].Rows[0][4].ToString();
txtstate.Text = ds.Tables[0].Rows[0][5].ToString();
}
protected void btnUpdate_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(connStr);
con.Open();
str = "update employee set EmpFname='" + txtFName.Text + "',EmpLname='" + txtLName.Text + "',Empcity='" + txtcity.Text + "',Empstate='" + txtstate.Text + "' where Empid=" + empid;
com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
int result = com.ExecuteNonQuery();
con.Close();
if (result == 1)
{
ScriptManager.RegisterStartupScript(this, this.GetType(), "ShowSuccess", "javascript:Display('" + lblFullName.Text + "')", true);
}
}
protected void btnCancel_Click(object sender, EventArgs e)
{
Response.Redirect("~/Default.aspx");
}
}
}
darsh antaniPosted Feb 25, 2013, 8:17 AM
this helped me.
darsh antaniPosted Feb 23, 2013, 10:36 PM
Satyapriya NayakPosted Feb 20, 2013, 11:24 AM