update gridview with single button

Jayakumars
Posted by Jayakumars under ASP.NET AJAX category on | Points: 40 | Views : 849
hi

i post the Gridview update gridview with single button.

string strConnString = ConfigurationManager.ConnectionStrings["CntString"].ConnectionString;
string str;
SqlCommand com;
SqlDataAdapter sqlda;
DataSet ds;
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
bindgrid("Select * from Tbl_Emp");
}
}
void bindgrid(string Qry)
{
SqlConnection con = new SqlConnection(strConnString);
con.Open();
str = Qry;


com = new SqlCommand(str, con);
sqlda = new SqlDataAdapter(com);
ds = new DataSet();
sqlda.Fill(ds, "student");


Grd1.DataSource = ds;
Grd1.DataBind();

con.Close();

}
protected void Button1_Click(object sender, EventArgs e)
{
str="Update Tbl_Emp Set Empname='CCC1' WHERE EmpId=2";
SqlConnection con = new SqlConnection(strConnString);
con.Open();
com = new SqlCommand(str, con);
com.ExecuteNonQuery();
bindgrid("Select * from Tbl_Emp");
}


<asp:GridView ID="Grd1" runat ="server" AutoGenerateColumns ="true">
</asp:GridView>

Comments or Responses

Login to post response