|
.net
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Trying to wire up dropdownlist in datagridI am trying to wire up the dropdownlist in a datagrid and use the onselectedindexchanged event however I am getting an "Object reference not set to an instance of an object" error when I try to load the page. Do you see the error? Thanks, Andy <asp:DropDownList ID="ddlType" AutoPostBack="True" OnSelectedIndexChanged="ddlType_SelectedIndexChanged" DataSource="<% #BindTypeDropDown()%>" DataTextField="short_description" DataValueField="code_value" Runat="server" /> protected System.Web.UI.WebControls.DropDownList ddlType; private void InitializeComponent() { this.Load += new System.EventHandler(this.Page_Load); this.ddlType.SelectedIndexChanged +=new EventHandler (ddlType_SelectedIndexChanged); <--Error points to this line } protected void ddlType_SelectedIndexChanged(object sender, EventArgs e) { Response.Write("hurray"); } Hi Andy,
Since you have OnSelectedIndexChanged="ddlType_SelectedIndexChanged", it will trigger ddlType_SelectedIndexChanged event. You don't need this.ddlType.SelectedIndexChanged +=new EventHandler (ddlType_SelectedIndexChanged); And in datagrid, there may be many 'ddlType', one in one row. HTH Elton Wang elton_w***@hotmail.com Show quoteHide quote "Andy Sutorius via DotNetMonster.com" wrote: > Hi, > > I am trying to wire up the dropdownlist in a datagrid and use the > onselectedindexchanged event however I am getting an "Object reference not > set to an instance of an object" error when I try to load the page. Do you > see the error? > > Thanks, > > Andy > > <asp:DropDownList ID="ddlType" AutoPostBack="True" > OnSelectedIndexChanged="ddlType_SelectedIndexChanged" DataSource="<% > #BindTypeDropDown()%>" DataTextField="short_description" > DataValueField="code_value" Runat="server" /> > > protected System.Web.UI.WebControls.DropDownList ddlType; > > private void InitializeComponent() > { > this.Load += new System.EventHandler(this.Page_Load); > this.ddlType.SelectedIndexChanged +=new EventHandler > (ddlType_SelectedIndexChanged); <--Error points to this line > } > > protected void ddlType_SelectedIndexChanged(object sender, EventArgs e) > { > Response.Write("hurray"); > } > > -- > Message posted via http://www.dotnetmonster.com >
Other interesting topics
Authentication mode in web.config causing crash.
Dynamically position custom control .ascx Message Box in ASP Options for generic full-text search without using database-specific full-text engine? how to make VS auto suggest properties during dev Firefox Validation Issue - not the standard document.[all] problem! Newbie on Session State Dataview returns 0 rows Unable to map the debug start page URL to a machine name User Controls in 2.0 |
|||||||||||||||||||||||