update gridview function

Topics: ASP.NET 2.0
Jul 25, 2011 at 5:17 AM
protected void grid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
    {
        // Get the new values from the GridView controls
        int i = grid.Rows[e.RowIndex].DataItemIndex;
        string title = ((TextBox)grid.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
        string author = ((TextBox)grid.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
        string review = ((TextBox)grid.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
        //string title = ((TextBox)grid.Rows[e.RowIndex].FindControl("txtIsbn")).Text;
        grid.EditIndex = -1;
        bindgriddata();
        // Update the XML file using the new values

        DataSet oDs = (DataSet)grid.DataSource;
        oDs.Tables[0].Rows[i][2] = title;
        oDs.Tables[0].Rows[i][3] = author;
        oDs.Tables[0].Rows[i][4] = review;
        oDs.WriteXml(Request.PhysicalApplicationPath + "RecomendedBooks.xml");
        bindgriddata();
    }
i am not getting the updated output if i write this code actually the thing i wanted is first i want to update the xml file when i edit the row and then the edited row must be updated.
please give the solution.thanking you in advance.
Jul 25, 2011 at 9:56 AM
Edited Jul 25, 2011 at 9:57 AM

@sharathshetty431:

Please a look at my blog post

http://code2code.info/post/crud-voi-linq2xml-using-xelement.aspx

any question you can contact.
Nguyen

Jul 25, 2011 at 11:22 AM

hello sir,thank u very much for the code but i dont think it matches with my code.can u please modify the above code or send the other code.

Jul 25, 2011 at 1:01 PM

its giving index out of range exception

Jul 25, 2011 at 5:55 PM

Hi sharathshetty431:

protected void grid_RowUpdating(object sender, System.Web.UI.WebControls.GridViewUpdateEventArgs e)
    {
        // Get the new values from the GridView controls
        int i = grid.Rows[e.RowIndex].DataItemIndex;
        string title = ((TextBox)grid.Rows[e.RowIndex].Cells[2].Controls[0]).Text;
        string author = ((TextBox)grid.Rows[e.RowIndex].Cells[3].Controls[0]).Text;
        string review = ((TextBox)grid.Rows[e.RowIndex].Cells[4].Controls[0]).Text;
        //string title = ((TextBox)grid.Rows[e.RowIndex].FindControl("txtIsbn")).Text;
        

        // Update the XML file using the new values

        DataSet oDs = (DataSet)grid.DataSource;
        oDs.Tables[0].Rows[i][2] = title;
        oDs.Tables[0].Rows[i][3] = author;
        oDs.Tables[0].Rows[i][4] = review;
        oDs.WriteXml(Request.PhysicalApplicationPath + "RecomendedBooks.xml");

        grid.EditIndex = -1;
        bindgriddata();
    }


I hope that will help
Regards,

Jul 26, 2011 at 5:56 AM

this also dint help.sir,do u have any other code.waiting for ur reply,sir.