update gridview with single button

Posted by Jammyhunt under ASP.NET on 3/20/2013 | Points: 10 | Views : 962 | Status : [Member] | Replies : 1
hello...

i have a gridview..

it is possible to update data of whole gridview with a single button?




Responses

Posted by: Jayakumars on: 3/20/2013 [Member] [MVP] Bronze | Points: 25

Up
0
Down
try this code
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>

Mark as Answer if its helpful to you

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

Login to post response