The post http://community.9cbs.net/expert/topic/3506/3506615.xml?temp =.5394251 mentioned a very interesting question.
[My DataGrid foot has a DROPDOWNLOAD control, if it is a button button, you can respond to the event of the Button button in the DataGrid DG_CARD_ITEMMAND event, E.CommandName == "ibutton_name" get
And I am now a DROPDOWNLOAD control, when it selects a record, how to trigger his incident]
I have also seen similar problems. Of course, I don't think there is an incident. But I found it in the template column, or the dropdownlist inside the header will not have the Grid ItemMand event. Can't get
This is a big misunderstanding. If there is no verification, I actually believe that other controls in Grid can only perform their own events by activating the Grid's Itemmand event. Floating, -_- #. So I just want to see how this question is.
Refer to some information (including SUNMAST's small sample blog), and discuss this JR with the drama, finally understand.
Reprinted SUNMAST blog
By icyer (our big bamboo) from 9cbs
First take a look at the time of these two events itemDatabase, Itemcreated
ItemDatabase, as long as the DATABIND method is executed, this event will immediately. Itemcreated, if the page is the first visit (page.ispostback = false), when executing Database for the first time, ItemCreated event first, that is, after DATABIND, first use itemcreated to create Header OK, then use itemDatabase to bind the Header line, then use itemcreated to create the first line, then call ItemDatabase to bind the first line, that is, itemcreated and itemdatabase are alternately executed. When the page returns, the itemcreated event will also be executed, but before Page_Load, it will not perform the itemDatabase.
When we write the program, there will be this page_loadif (! Page.ispostback) {dataGrid1.datasouce = ........; DataGrid1.Database ();
So, when the page is loaded for the first time, we have implemented this itemDATABOUND event. But when the page is raised, this itemdatabase event is no longer executed. As we all know, ViewState does not remember the control of the control, and only remembers some properties. The recovery of the event is based on the initializecomponent () method.
So, if you register the DropDownList's event, put it in the itemDatabase method, page a postback, the event is lost immediately. However, if you register the DropDownList's event, put it in the itemcreated method, even if the page postback, the event will not be lost, because Page_Load, re-call this itemcreated method, this method is not limited by ISPostback. At this point, this problem is very clear.
However, because each page postback is executed, it must be executed, so it will definitely affect efficiency. So, can we give another solution. The drama is proposed, and you can give this DropDownList registration event during editing. Of course, in the Grid template column, click on the lightning symbol of this dropdownlist without an event to choose, but we can change his HTML
In this way, we don't have to dynamically register this DropDonwlist. We just need to bind its data in the itemDatabase method. PS: Don't forget to set the DDL_SELECTEDEXCHANGED.