using System; using System.Collections; using System.Configuration; using System.Data; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; publicpartialclass Default2 : System.Web.UI.Page { protectedvoid Page_Load(object sender, EventArgs e) { } protectedvoid Button1_Click(object sender, EventArgs e) { List<Test> l =new List<Test>(); foreach (GridViewRow row inthis.GridView1.Rows) { int ID = Convert.ToInt32(this.GridView1.DataKeys[row.RowIndex].Value); string Name = ((TextBox)row.FindControl("txtName")).Text+"rile"; Test t =new Test(); t.ID = ID; t.Name = Name; l.Add(t); } TestManager.Update(l[0], l[1]); this.GridView1.DataBind(); } protectedvoid GridView1_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { Test t = (Test)e.Row.DataItem; Label lblID = (Label)e.Row.FindControl("lblID"); lblID.Text = t.ID.ToString(); TextBox txtName = (TextBox)e.Row.FindControl("txtName"); txtName.Text = t.Name; } } }
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; /**////<summary> /// Summary description for Test ///</summary> publicclass Test { privateint _ID; privatestring _Name; publicint ID { get { returnthis._ID; } set { this._ID = value; } } publicstring Name { get { returnthis._Name; } set { this._Name = value; } } }
using System; using System.Data; using System.Configuration; using System.Linq; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; using System.Xml.Linq; using System.Collections.Generic; /**////<summary> /// Summary description for TestManager ///</summary> publicclass TestManager { publicstatic Test t1; publicstatic Test t2; publicstatic List<Test> GetTests() { List<Test> l =new List<Test>(); if (t1 ==null) { t1 =new Test(); t1.ID =1; t1.Name ="ri"; } l.Add(t1); if (t2 ==null) { t2 =new Test(); t2.ID =2; t2.Name ="rio"; } l.Add(t2); return l; } publicstaticvoid Update(Test t3, Test t4) { t1 = t3; t2 = t4; } }