Hello

I'm currently trying to get my GridView to update all rows at the same time.

The gridview takes data from an .XML file - I can use the 'onRowEditing' to update a single row at a time - however I want it to be able to update all rows at the same time.

What is the best approach for this - I currently use a 'showEditButton' button but as said this only updates a single row.

What would be the easiest way to update all rows - can I use a textbox in the gridview rather than a label and just have an 'Update' button.

Here is my current 'Updatedata' which is linked to the edit button.

DataSet ds = new DataSet();
        ds.ReadXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
        foreach (DataColumn dc in ds.Tables[0].Columns)
        {
            dc.ColumnMapping = MappingType.Attribute;
        }
        int i = e.RowIndex;
        string sDataField = (gv.Rows[e.RowIndex].FindControl("txtDataField") as TextBox).Text;
        string sHeader = (gv.Rows[e.RowIndex].FindControl("txtHeader") as TextBox).Text;
        string sUseDefaults = (gv.Rows[e.RowIndex].FindControl("txtUseDefaults") as TextBox).Text;
        string sSortOrder = (gv.Rows[e.RowIndex].FindControl("txtSortOrder") as TextBox).Text;
        gv.EditIndex = -1;
        binddata();
        DataView dv = new DataView(ds.Tables[0]);
        gv.DataSource = dv;
        //Lets add some random data into the first column to prove that I can auto create the Axx ID up to A99
        ds.Tables[0].Rows[i]["DataField"] = sDataField;
        ds.Tables[0].Rows[i]["Header"] = sHeader;
        ds.Tables[0].Rows[i]["UseDefaults"] = sUseDefaults;
        ds.Tables[0].Rows[i]["SortOrder"] = sSortOrder;
        ds.WriteXml(Server.MapPath(@"xml\" + Request["Gradebook"] + ".xml"));
        binddata();
        Page.Response.Redirect(Page.Request.Url.ToString(), true);

you can update one by one grid row using "update" button in each row

you can also update whole grid using single update button. Onclick of this button call
for each( grid items ) loop and update one by one rows in database or xml

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.