Trying to wire up dropdownlist in datagrid

  • Thread starter Andy Sutorius via DotNetMonster.com
  • Start date
A

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");
}
 
G

Guest

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
(e-mail address removed)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top