i have already sent u the frontend code.
this is my compleate C# code
public partial class institutedatails : System.Web.UI.Page
{
int userid1;
SqlConnection con = new SqlConnection(Class1.con);
protected void Page_Load(object sender, EventArgs e)
{
if (!this.IsPostBack)
{
this.BindGrid();
}
}
private void BindGrid()
{
using ( SqlConnection con = new SqlConnection(Class1.con))
{
using (SqlCommand cmd = new SqlCommand("select * from Uregistration where icode='" + txtxcode.Text + "'"))
{
using (SqlDataAdapter sda = new SqlDataAdapter())
{
cmd.Connection = con;
sda.SelectCommand = cmd;
using (DataTable dt = new DataTable())
{
sda.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
}
}
}
}
}
protected void gridview_data(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(Class1.con);
con.Open();
string query = "select * from Uregistration where icode='" + txtxcode.Text + "'";
SqlCommand com = new SqlCommand(query, con);
SqlDataReader dr;
dr = com.ExecuteReader();
if (dr.HasRows)
{
dr.Read();
BindGrid();
GridView1.Visible = true;
txtxcode.Text = "";
}
else
{
GridView1.Visible = false;
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Invalid Institue Code');", true);
}
}
protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView1.EditIndex = e.NewEditIndex;
this.BindGrid();
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
SqlConnection con = new SqlConnection(Class1.con);
// userid1 = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);
// Label lblstid = (Label)GridView1.Rows[e.RowIndex].FindControl("lblstId");
TextBox txtiname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtiname.Trim()");
TextBox txticode = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtcode.Trim()");
TextBox txtname = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtname.Trim()");
TextBox txtaddr = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtaddr.Trim()");
TextBox txtgender = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtgender.Trim()");
TextBox txtoccup = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtoccup.Trim()");
TextBox txtmob = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtmob");
TextBox txtemail = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtemail");
TextBox txtuser = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtuser");
TextBox txtpass= (TextBox)GridView1.Rows[e.RowIndex].FindControl("txtpass");
TextBox txthint = (TextBox)GridView1.Rows[e.RowIndex].FindControl("txthint");
con.Open();
SqlCommand cmd = new SqlCommand("Update Uregistration set iname='" + txtiname.Text.Trim() + "',icode='" + txticode.Text.Trim() + "',name='" + txtname.Text.Trim() + "',address='" + txtaddr.Text.Trim() + "',gender='" + txtgender.Text.Trim() + "',occupation='" + txtoccup.Text.Trim() + "',mob='" + txtmob.Text.Trim() + "',email='" + txtemail.Text.Trim() + "',username='" + txtuser.Text.Trim() + "',password='" + txtpass.Text.Trim() + "',hint='" + txthint.Text.Trim() + "' where userid= '" + Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value) + "'", con);
cmd.ExecuteNonQuery();
con.Close();
ScriptManager.RegisterStartupScript(this, this.GetType(), "Message", "alert('Data Updated Successfully');", true);
GridView1.EditIndex = -1;
BindGrid();
}
protected void GridView1_RowCancelingEdit(object sender, EventArgs e)
{
GridView1.EditIndex = -1;
this.BindGrid();
}
}