-1

I have one list.in that list title column,Start date ,Due DAte ,Assigned To,Status column is there.And some entries also there.All the list items i am displaying in one grid.After that in that grid Status column i need to change as editable.Aftet that one button is there named as save.On click of save that particular row should change in list also.For example in Particular row status column i am changing as completed then in list also it should update as completed.Just imagine i have 3 rows.3 rows i edited the status as completed.After click save button in list also 3 rows should change as completed.

if login name =assigned to person then that particular row i am displaying in grid through c#.After that i tried to edit in the grid the from dropdown status column as completed.I have save button also.but i don't know how to update that in list.Is it possible? Because as far as i know in event receiver only i can update the list item.But i am trying in Custom web part.If it is possible Can u give c# code?

2
  • It’s pretty hard to understand what you are asking. Can you add screenshots, schemas, flows?
    – jleture
    Dec 10, 2023 at 10:35
  • In my sharepoint site i have one list.In that list i have some list items.all the items i am displaying in grid(custom web part).In that grid one column i have to edit.And that editable value i should update in my list item.I can't add screen shot.My organization is not allowed to use internet.In my home only i am using internet.I need result immediately. Dec 10, 2023 at 13:08

1 Answer 1

0

Using ASP.net: https://www.c-sharpcorner.com/UploadFile/1e050f/edit-and-update-record-in-gridview-in-Asp-Net/

First, you need to add an EditItemTemplate in the TemplateField that specifies a custom user interface (UI) for the item in edit mode then RowUpdating to update the list. Try this sample code, replace YourDbContext with the name of your DbContext, and YourList with the name of your list. Also, replace DropDownList1 with the ID of your DropDownList. Try and let me know if this works for you.

protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
    // Get the new values from the GridView row
    string newStatus = ((DropDownList)GridView1.Rows[e.RowIndex].FindControl("DropDownList1")).SelectedValue;

    // Get the ID of the item to update
    int id = Convert.ToInt32(GridView1.DataKeys[e.RowIndex].Value);

    // Use Entity Framework to update the database
    using (YourDbContext db = new YourDbContext())
    {
        // Find the item in the database using the ID
        var item = db.YourList.Find(id);

        // Update the status
        item.Status = newStatus;

        // Save the changes to the database
        db.SaveChanges();
    }

    // Rebind the GridView to show the changes
    GridView1.DataBind();
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.