can we do this without using querystring,,,please provide me 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.SqlClient; using System.Data; using System.Configuration; namespace WebApplication1 { public partial class editpage : System.Web.UI.Page { SqlConnection conn = new SqlConnection(@"Data Source=SRAVI-PC\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=True"); protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { BindDetails(); } } private void BindDetails() { lblid.Text = Request.QueryString["Id"]; // txtid.Text = Request.QueryString["Id"]; txtfname.Text = Request.QueryString["FirstName"]; txtlname.Text = Request.QueryString["LastName"]; } protected void btnsave_Click(object sender, EventArgs e) { int id1 = Convert.ToInt32(lblid.Text); // int id = Convert.ToInt32(txtid.Text); string fna = txtfname.Text; string lna = txtlname.Text; string cmd = "update namestb set FirstName='" + fna + "',LastName='"+lna+"'where Id="+id1; SqlCommand command = new SqlCommand(cmd, conn); conn.Open(); command.ExecuteNonQuery(); conn.Close(); Response.Redirect("displaypage.aspx"); } protected void btncancel_Click(object sender, EventArgs e) { Response.Redirect("displaypage.aspx"); } } }
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; namespace WebApplication1 { public partial class displaypage : System.Web.UI.Page { SqlConnection conn = new SqlConnection(@"Data Source=SRAVI-PC\SQLEXPRESS;Initial Catalog=testdb;Integrated Security=True"); protected void Page_Load(object sender, EventArgs e) { getdata(); } public void getdata() { string cmd = "select * from namestb"; SqlDataAdapter da = new SqlDataAdapter(cmd, conn); DataSet ds = new DataSet(); da.Fill(ds); GridView1.DataSource = ds.Tables[0]; GridView1.DataBind(); } protected void edit(object sender,CommandEventArgs z) { if (z.CommandName == "edit") { int id = Convert.ToInt32(z.CommandArgument); SqlDataAdapter da = new SqlDataAdapter("select * from namestb where Id=" + id, conn); DataSet ds = new DataSet(); da.Fill(ds, "namestb"); DataTable dt = new DataTable(); dt = ds.Tables[0]; int Id = Convert.ToInt16(dt.Rows[0]["Id"]); string FirstName = Convert.ToString(dt.Rows[0]["FirstName"]); string LastName = Convert.ToString(dt.Rows[0]["LastName"]); Response.Redirect("editpage.aspx?Id=" + Id + "&FirstName=" + FirstName + "&LastName=" + LastName); } } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)