Home All Groups Group Topic Archive Search About

Trying to wire up dropdownlist in datagrid

Author
10 Jun 2005 5:17 PM
Andy Sutorius via DotNetMonster.com
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

Author
10 Jun 2005 7:15 PM
Elton W
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
>

Bookmark and Share