Search code examples
c#asp.netlistviewupdating

How do I alter the value being updated in a ListView?


I can't seem to find an answer to this, maybe I'm not using the correct terminology.

I have a ListView that is editable, I want it so that if a user clicks on Edit and then Update, that the field is updated with the value from another textbox, not the field they are editing.

The reason for this is that I have a Colour Picker that alters the value of a textbox, when they click Update I want this value to be the updated value.

I guess I utilise the ItemUpdating event, but I don't have much in the way of code because I'm pretty lost. I have this so far:

protected void ListView2ItemUpdating(object sender, ListViewUpdateEventArgs e)
{
  var selectedItem = ListView2.Items[ListView2.EditIndex];

// I have no idea what to put here
 something = ColourChosen.Value;
}

Here is an image that I hope will make what I'm trying to do a little more understandable:

ListView2

If any one could point me in the right direction of any examples, that would be much appreciated.


Solution

  • Although this doesn't answer my initial question this does what I want to happen.

    What I should be doing is altering the database that ListView is attached to.

    I use this code:

    protected void ListView2ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
      using (var myEntities = new i96X_utilEntities())
      {
        var myPlotColour = (from plotC in myEntities.PlotColours
                            where plotC.ID == selectedID
                            select plotC).Single();
        myPlotColour.PlotColour1 = ColourChosen.Value;
        myEntities.SaveChanges();
      }
    }
    

    So, even though I have no idea how to intercept a field being updated in a ListView, in this example I don't need to.