0

I have a ComboBox binded to an object that is also binded to a DataGrid. When I change the ComboBox selection or the SelectedItem in the DataGrid the event SelecionChanged at the ComboBox is triggered.

Is there a way to know which component (DataGrid or ComboBox) has triggered the event?

Guilherme Campos
  • 369
  • 7
  • 20
  • Events have a `sender` and an `e` associated with them. The `sender` is what will tell you who invoked the event. – Brian Jun 24 '13 at 19:01
  • I've also tried using the sender, but the sender type is always ComboBox. Don't know why. And I've also tried using DataGrid SelectionChanged event to set a flag to be handled in ComboBox SelectionChanged event, but DataGrid SelectionChanged is triggered after ComboBox SelectionChanged. – Guilherme Campos Jun 24 '13 at 19:06

4 Answers4

1

In order for the ComboBox to post back, I'd imagine it's set to AutoPostBack? If this affects the data on the GridView at all, then all events will fire. When a full postback is triggered (such as with the ComboBox set to AutoPostBack=true), every event with new data is fired.

You should look into the control lifecycle: http://msdn.microsoft.com/en-us/library/aa719775(v=vs.71).aspx (this is just the msdn doc, it's not great, but it's a good starting point).

...You should also try and post some code with your question :) It's a little ambiguous what you're doing. What object are they both bound to? Or is the same dataset bound to both the GridView and ComboBox?

EDIT: This post might help a little: Two types of postback events

Community
  • 1
  • 1
withoutIf
  • 126
  • 8
0

If I were you, I would place the breakpoints at the SelectedItem or the SelectedChanged breakpoints and tried to run the solution in debug mode and take a look the places where the first one breakpoint was hit ;) Callstack will help you also.

0

Assuming you have them both hooked up to a object data source. You can just create a seperate data source for your drop down that uses the same SelectMethod. That way they both get updated with the same data after a postback.

Otherwise Use javascript for the onchange event of the drop down and set a hidden field with if was changed or not. Then check that value to see if it was from the drop down or not.

<asp:DropDownList runat="server" ID="drpOption"onchange="javascript:OptionChanged();"></asp:DropDownList>

function OptionChanged() {
    $('#hdnField').val = 'true';

    return false;
}
Josh Allen
  • 124
  • 1
  • 4
0

U can make Selection change event of both DAtaGRid and Combobox ANd check by applying BreakPoint which part executes first..!!

Vishal
  • 604
  • 1
  • 12
  • 25