![]() |
|
|
|||||||
![]() |
ASP Net - RE: How to capture SelectedIndexchanged event of dropdownlist in Datag |
|
|
Thread Tools | Search this Thread |
|
|
#1 |
|
The main problem is that the DropDownList's events couldn't be handled
directly by the page because it is in the DataGrid. The "cleanest" solution is : 1/ Create a custom dropdownlist by inherist from the System.Web.UI.WebControls.DropDownList. 2/ Add the CommandName and CommandArgument properties 3/ Override the OnSelectIndexChanged method 4/ In your .aspx Page : a. Set the DropDownList AutoPostback property to true b. Set the CommandName and the CommandArgument of your DropDownList b. Handle the ItemCommand of the DataGrid c. Write the code that you must be execute when the event is fire Sample : public class CustomDropDownList : System.Web.UI.WebControls.DropDownList, IPostBackEventHandler { #region Properties [Bindable(false), Category("Behavior")] public string CommandName { get { object o = ViewState["CommandName"]; if (o != null) return (string) o; return ""; } set { ViewState["CommandName"] = value; } } [Bindable(true), Category("Behavior")] public string CommandArgument { get { object o = ViewState["CommandArgument"]; if (o != null) return (string) o; return ""; } set { ViewState["CommandArgument"] = value; } } #region Methods protected override void OnSelectedIndexChanged(EventArgs e) { base.RaiseBubbleEvent(this, new CommandEventArgs(this.CommandName, this.CommandArgument)); base.OnSelectedIndexChanged (e); } #endregion } The RaiseBubbleEvent methods allows you to propagate the Command event to the DataGrid control, that raise the ItemCommand. =?Utf-8?B?Vmtv?= |
|
|
|
|
#2 |
|
Posts: n/a
|
oups, do not implements the IPostBackEventHandler interface.
"Vko" wrote: > The main problem is that the DropDownList's events couldn't be handled > directly by the page because it is in the DataGrid. > > The "cleanest" solution is : > > 1/ Create a custom dropdownlist by inherist from the > System.Web.UI.WebControls.DropDownList. > 2/ Add the CommandName and CommandArgument properties > 3/ Override the OnSelectIndexChanged method > 4/ In your .aspx Page : > a. Set the DropDownList AutoPostback property to true > b. Set the CommandName and the CommandArgument of your DropDownList > b. Handle the ItemCommand of the DataGrid > c. Write the code that you must be execute when the event is fire > > Sample : > > public class CustomDropDownList : System.Web.UI.WebControls.DropDownList, > IPostBackEventHandler > { > #region Properties > [Bindable(false), Category("Behavior")] > public string CommandName > { > get > { > object o = ViewState["CommandName"]; > if (o != null) > return (string) o; > return ""; > } > set > { > ViewState["CommandName"] = value; > } > } > [Bindable(true), Category("Behavior")] > public string CommandArgument > { > get > { > object o = ViewState["CommandArgument"]; > if (o != null) > return (string) o; > return ""; > } > set > { > ViewState["CommandArgument"] = value; > } > } > > #region Methods > protected override void OnSelectedIndexChanged(EventArgs e) > { > base.RaiseBubbleEvent(this, new CommandEventArgs(this.CommandName, > this.CommandArgument)); > base.OnSelectedIndexChanged (e); > } > > #endregion > } > > The RaiseBubbleEvent methods allows you to propagate the Command event to > the DataGrid control, that raise the ItemCommand. =?Utf-8?B?Vmtv?= |
|
![]() |
| Thread Tools | Search this Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| RIP HD-DVD? - HD-DVD CES Event Canceled | Air Raid | DVD Video | 0 | 01-05-2008 03:06 AM |
| SuperVideoCap work as a broadcast capture and screen capture and record tool. | hely0123 | Media | 0 | 10-30-2007 08:59 AM |
| Capture satellite(direct tv,tv,vcr) with ati all in wonder pro 128HELP!! | danester(NOSPAM) | DVD Video | 6 | 03-02-2004 06:13 AM |
| SUPER BOWL GALA EVENT, tickets available | TheLeiterSideYGB | DVD Video | 1 | 01-06-2004 11:55 PM |