eramgarden Posted April 1, 2004 Posted April 1, 2004 I have a datagrid with 5 Updateble textfields on it. Right now, this is what I do: When user updates ONE field, in the code behind, I take ALL 5 fields and do an update because I can't tell which text field they chose to update This is what I want to do... Somehow figure out which fields were chosen and build my update based on those fields only... Any thoughts? Quote
cyclonebri Posted April 1, 2004 Posted April 1, 2004 (edited) I have a datagrid with 5 Updateble textfields on it. Right now, this is what I do: When user updates ONE field, in the code behind, I take ALL 5 fields and do an update because I can't tell which text field they chose to update This is what I want to do... Somehow figure out which fields were chosen and build my update based on those fields only... Any thoughts? Robby just gave me the code to find the new values in the textbox, and you can do that by using this example (as posted by Robby): dim txt as textbox = CType(e.Item.Cells(1).Controls(0), TextBox) myNewSomething = CType(txt.Text, Integer) or in a EditItemTemplate of a TemplateColumn dim dd as dropdownlist = CType(e.Item.FindControl("myDropDown"), DropDownList) myNEwSomwthing = CType(dd.SelectedItem.Value, Integer) Then you can get the original values from the dataset that you used to fill the columns like this (you can do this in the update event and it will work just fine, as long as you have populated your dataset on the postback (which you will need to then NOT rebind the grid on the postback, or your textboxes will not have the updated data): m_myOldVals(0) = m_myDS.Tables(0).Rows(e.Item.ItemIndex).Item("SomeField") m_myOldVals(1) = m_myDS.Tables(0).Rows(e.Item.ItemIndex).Item("SomeOtherField") '... m_myOldVals(4) = m_myDS.Tables(0).Rows(e.Item.ItemIndex).Item("YetAnotherField") Then you can just compare and wherever the value has changed you can do the update! Good Luck, Brian Edited April 1, 2004 by cyclonebri Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.