how to get text of girdview textbox in asp.net

Posted by Shanky11 under ASP.NET on 12/21/2012 | Points: 10 | Views : 559 | Status : [Member] | Replies : 2
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
{
if (e.CommandName.Equals("add"))
{
string newname = ((TextBox)GridView1.FooterRow.FindControl("txtnewUserName")).Text.Trim();
TextBox t = GridView1.FooterRow.FindControl("txtUserage") as TextBox;
string s = t.Text;
//SqlConnection con = new SqlConnection("data source=shankar-pc\\shankar ; initial catalog=master;user id= sa;password=password@1");
// con.Open();
//con.Close();
ClientScript.RegisterStartupScript(Page.GetType(), "acknowledgement", "<script>alert('Record inserted successfully!!!!!!!!')</script>");
}
}




Responses

Posted by: Pavanandey on: 12/21/2012 [Member] Bronze | Points: 25

Up
0
Down
TextBox txtRemarks = new TextBox();
txtRemarks = (TextBox)selectedRow.FindControl("txtRemarks");

// string text = txtRemarks.Text


Thanks
Pavan Kumar
Mark Answer if this fits the need

Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ankitsrist on: 12/24/2012 [Member] Starter | Points: 25

Up
0
Down
 protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)

{
dbc.myconnection();
if (e.CommandName.Equals("insert"))
{
TextBox txt1 = (TextBox)GridView1.FooterRow.FindControl("txtn");
TextBox txt2 = (TextBox)GridView1.FooterRow.FindControl("txtd");
SqlCommand cmd = new SqlCommand("insert into dmlwithingrid(name, decription)values('"+txt1.Text +"', '"+txt2.Text +"')", dbc .sqlcon );
cmd.ExecuteNonQuery();
fillgrid();

}

}


Shanky11, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response