简体   繁体   中英

How to get DataGrid SelectionChanged trigger source component?

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?

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

如果我是您,我会将断点放置在SelectedItem或SelectedChanged断点处,并尝试在调试模式下运行解决方案,并查看击中第一个断点的位置;)Callstack也会为您提供帮助。

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;
}

您可以通过应用首先执行的BreakPoint来使DAtaGRid和Combobox ANd检查选择更改事件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM