i use gridview where all date are retrieve from sql database,i use templete field and there is two textbox , i want when we change the value of textbox which is inside a gridview the value is changed when we click the save button...........
plese help me
page load event
Expand|Select|Wrap|Line Numbers
- if (!IsPostBack)
- {
- string query = Request.QueryString["id"].ToString();
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["discussionForum"].ConnectionString);
- con.Open();
- SqlCommand cmd = new SqlCommand("SELECT tblReguser.photo, tblReguser.username,tblComment.id, tblComment.timestamp,tblComment.description,tblComment.relevance FROM tblRegUser CROSS JOIN tblComment WHERE (tblComment.topic_id = @id and tblComment.user_id=tblReguser.id and tblComment.status='0')", con);
- cmd.Parameters.AddWithValue("@id", query);
- SqlCommand cmd1 = new SqlCommand("SELECT tblReguser.photo, tblReguser.username,tblComment.id, tblComment.timestamp,tblComment.description,tblComment.relevance FROM tblRegUser CROSS JOIN tblComment WHERE (tblComment.topic_id = @id and tblComment.user_id=tblReguser.id and tblComment.status='1')", con);
- cmd1.Parameters.AddWithValue("@id", query);
- SqlDataAdapter adp = new SqlDataAdapter(cmd1);
- DataSet ds = new DataSet();
- adp.Fill(ds);
- GridView3.DataSource = ds;
- GridView3.DataBind();
- SqlDataReader rdr = cmd.ExecuteReader();
- GridView1.DataSource = rdr;
- GridView1.DataBind();
- con.Close();
- }
Expand|Select|Wrap|Line Numbers
- protected void saveunblock_Click(object sender, EventArgs e)
- {
- Button lnk = sender as Button;
- string a = lnk.CommandArgument;
- foreach (GridViewRow row in GridView1.Rows)
- {
- if (row.RowType == DataControlRowType.DataRow)
- {
- TextBox t = (TextBox)row.FindControl("t2");
- CheckBox c = (CheckBox)row.FindControl("c2");
- string a1 = System.DateTime.Now.ToString();
- string myvalue = (string)Session["mykey"];
- SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["discussionForum"].ConnectionString);
- con.Open();
- if (c.Checked == true)
- {
- SqlCommand cmd = new SqlCommand("update tblComment set status='0' where id=@id", con);
- cmd.Parameters.AddWithValue("@id", a);
- cmd.ExecuteNonQuery();
- con.Close();
- Response.Redirect("admintopic.aspx");
- }
- }
- }
- }