Go Back   Velocity Reviews > Newsgroups > ASP Net
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

Reply

ASP Net - RE: How to capture SelectedIndexchanged event of dropdownlist in Datag

 
Thread Tools Search this Thread
Old 12-23-2004, 01:19 PM   #1
Default RE: How to capture SelectedIndexchanged event of dropdownlist in Datag


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?=
  Reply With Quote
Old 12-23-2004, 01:21 PM   #2
=?Utf-8?B?Vmtv?=
 
Posts: n/a
Default RE: How to capture SelectedIndexchanged event of dropdownlist in D
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?=
  Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off

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




SEO by vBSEO 3.3.2 ©2009, Crawlability, Inc.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46