i have two textbox, one button and one gridview what i want is when user enter details in those two textbox and press on submit button it will show in the gridview. In my grid i have an edit link so that when i click on edit link that row data can be seen in those two textboxes using query string and submit button change to update button and after making some changes when user click on update button it will update data in the grid and database too
here what i have done till yet
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
this.BindGrid();
string ID = Request.QueryString["ID"];
cmd = new SqlCommand("Select * from UserDetails where ID='" + ID + "'", con);
con.Open();
ad = new SqlDataAdapter(cmd);
dt.Clear();
ad.Fill(dt);
if (dt.Rows.Count > 0)
{
tbid.Text = ID;
TextBox1.Text = dt.Rows[0][1].ToString();
TextBox2.Text = dt.Rows[0][2].ToString();
}
con.Close();
}
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True");
con.Open();
string Name = TextBox1.Text;
string Place = TextBox2.Text;
using (SqlCommand cmd = con.CreateCommand())
{
cmd.CommandText = "insert into UserDetails(Name,Place) values('" + Name + "','" + Place + "')";
cmd.Parameters.AddWithValue("@Name", TextBox1.Text);
cmd.Parameters.AddWithValue("@Place", TextBox2.Text);
cmd.ExecuteNonQuery();
}
con.Close();
GridView1.DataSource = dt;
GridView1.DataBind();
TextBox1.Text = string.Empty;
TextBox2.Text = string.Empty;
}
private void BindGrid()
{
con.Open();
ad = new SqlDataAdapter("Select * from UserDetails where Name=Name", con);
ad.Fill(dt);
GridView1.DataSource = dt;
GridView1.DataBind();
con.Close();
}
}
when user enter some data in the input field it will store in the database but it will not instantly show in the grid
second think when i click on edit link my data will be shown in the textboxex using query string but now i want to update that data but i want to use same submit button with text change to update after click on edit link