1
votes

I am trying to update multiple records from a gridview where one row updates multiple records in a ASP.NET webpage.

To Clarify -

ID  MyDate  TeamName    Attribute
1   09/04/2014  Team A  Some Attribute
2   08/04/2014  Team B  Some Attribute
3   07/04/2014  Team A  Some Attribute

Gridview pulls record 1 but hides the ID and MyDate field so they have a template view to modify.

If user changes the Attribute field to read 'Different Attribute' from 'Some Attribute'; I'd like it to update records 1 & 3 Attribute field to read 'Different Attribute'.

Desired Result:

ID  MyDate  TeamName    Attribute
1   09/04/2014  Team A  Different Attribute
2   08/04/2014  Team B  Some Attribute
3   07/04/2014  Team A  Different Attribute

Current Update Method:

originalDataTable = (System.Data.DataTable)ViewState["originalValuesDataTable"];
    foreach (GridViewRow r in GridView1.Rows)
    if (((CheckBox)r.FindControl("CheckBox1")).Checked)
    {
        if (IsRowModified(r))

            { GridView1.UpdateRow(r.RowIndex, false); }


    }

Here is my update command & all parameters are set:

                UpdateCommand="UPDATE METRICS 
                            SET
                                OWNER_INTERACTOR = :OWNER_INTERACTOR, 
                                BACKUP_INTERACTOR = :BACKUP_INTERACTOR, 
                                METRIC_DESCRIPTION = :METRIC_DESCRIPTION, 
                                OFFICE = :OFFICE, 
                                BUS_FUNCTION = :BUS_FUNCTION, 
                                TEAM = :TEAM, 
                                BUS_PROCEDURE = :BUS_PROCEDURE, 
                                SUB_PROCESS = :SUB_PROCESS, 
                                INITIATIVE = :INITIATIVE, 
                                MISC_TEXT = :MISC_TEXT, 
                                TIME_STAMP = :TIME_STAMP, 
                                ACTIVE_INDICATOR = :ACTIVE_INDICATOR,
                                END_TIME = :END_TIME, 
                                START_TIME = :START_TIME,  
                                FP_5_CATEGORY = :FP_5_CATEGORY, 
                                PS2I_CATEGORY = :PS2I_CATEGORY, 
                                CLIENT = :CLIENT 
                            WHERE 
                                (DIVISION = :DIVISION) AND 
                                (SERVICE = :SERVICE) AND 
                                (PROCESS = :PROCESS) AND 
                                (METRIC_TYPE = :METRIC_TYPE) AND 
                                (METRIC_NAME = :METRIC_NAME)"

But the problem is the "UpdateRow" only updates that row given the GridView DataKeyName which I have to omit to update multiple records.

So how do I make a UpdateRow really update multiple rows?

Also I know db conventions are out the window here. I'm on the business side and IT only gave me one table on Oracle which I inherited that a business user designed.

Thanks in Advance!

1

1 Answers

0
votes

For Others, I found you can edit the parameters, whether they are DataKeyNames or not via the object events. In my case it's the on updating event, but I think they have to qualify the parameter by it's index when updating it's value.

    protected void dsFilteredData_Updating(object sender, SqlDataSourceCommandEventArgs e)
{
    e.Command.Parameters.RemoveAt("original_ID");
    e.Command.Parameters[4].Value = parammt;
    e.Command.Parameters[22].Value = origparamt;
}