1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
test_DAO dao = new test_DAO();
DataSet ds = dao.findAll();
DataTable dt = ds.Tables[0];
GridView2.DataSource = dt;
GridView2.DataBind();
Session["test"] = GridView2.DataSource;
}
else
{
GridView2.DataSource = Session["test"];
}
}
protected void GridView2_RowEditing(object sender, GridViewEditEventArgs e)
{
GridView2.EditIndex = e.NewEditIndex;
GridView2.DataBind();
}
protected void GridView2_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
GridViewRow row = GridView2.Rows[e.RowIndex];
DataTable dt = (DataTable)Session["test"];
dt.Rows[e.RowIndex]["name"] = ((TextBox)row.FindControl("TxtName")).Text;
dt.Rows[e.RowIndex]["firstname"] = ((TextBox)row.FindControl("TxtFirstname")).Text;
dt.Rows[e.RowIndex]["age"] = int.Parse(((TextBox)row.FindControl("TxtAge")).Text);
dt.Rows[e.RowIndex]["comment"] = ((TextBox)row.FindControl("TxtComment")).Text;
GridView2.EditIndex = -1;
GridView2.DataBind();
}
protected void GridView2_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
{
GridView2.EditIndex = -1;
GridView2.DataBind();
}
protected void Button1_Click(object sender, EventArgs e)
{
DataTable dt = (DataTable)Session["test"];
foreach(DataRow row in dt.Rows)
{
if (row.RowState == DataRowState.Modified)
{
//Update
}
}
} |
Partager