| Author: Sree Harsha 27 Apr 2009 | Member Level: Bronze Points : 2 |
I have written code for filling dataset with xml document and associate the same to gridview.
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { binddata(); } } void binddata() { DataSet ds = new DataSet(); ds.ReadXml(Server.MapPath(”empdata.xml”)); gv.DataSource = ds; gv.DataBind(); } protected void Editdata(object s, GridViewEditEventArgs e) { gv.EditIndex = e.NewEditIndex; binddata(); } protected void Deletedata(object s, GridViewDeleteEventArgs e) { binddata(); DataSet ds= gv.DataSource as DataSet; ds.Tables[0].Rows[gv.Rows[e.RowIndex].DataItemIndex].Delete(); ds.WriteXml(Server.MapPath(”empdata.xml”)); binddata (); } protected void Canceldata(object s, GridViewCancelEditEventArgs e) { gv.EditIndex = -1; binddata(); } protected void Updatedata(object s, GridViewUpdateEventArgs e) { int i = e.RowIndex; string id=(gv.Rows[e.RowIndex].FindControl(”txtid”) as TextBox).Text; string name=(gv.Rows[e.RowIndex].FindControl(”txtname”) as TextBox).Text; string city=(gv.Rows[e.RowIndex].FindControl(”txtcity”) as TextBox).Text; string salary=(gv.Rows[e.RowIndex].FindControl(”txtsalary”) as TextBox).Text; gv.EditIndex = -1; binddata(); DataSet ds =(DataSet) gv.DataSource; ds.Tables[0].Rows[i]["empid"] = id; ds.Tables[0].Rows[i]["empname"] = name; ds.Tables[0].Rows[i]["empcity"] = city; ds.Tables[0].Rows[i]["empsalary"] = salary; ds.WriteXml(Server.MapPath(”empdata.xml”)); binddata(); } protected void pageddata(object s, GridViewPageEventArgs e) { gv.PageIndex = e.NewPageIndex; binddata(); } protected void insert(object sender, EventArgs e) { binddata(); DataSet ds = gv.DataSource as DataSet; DataRow dr = ds.Tables[0].NewRow(); dr[0] = empId.Text; dr[1] = empName.Text; dr[2] = empcity.Text; dr[3] = empsalary.Text; ds.Tables[0].Rows.Add(dr); ds.AcceptChanges(); ds.WriteXml(Server.MapPath(”empdata.xml”)); binddata(); empId.Text = string.Empty; empcity.Text = string.Empty; empName.Text = string.Empty; empsalary.Text = string.Empty; }
|
| Author: Kirankumar Potnuru 15 May 2009 | Member Level: Gold Points : 1 |
Do you have any idea for data binding for data grid at device aplication (compact framework 2.0 or greater versions) and data is coming from xml not from data base......!!!!
|