473,407 Members | 2,320 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Trying to wire up dropdownlist in datagrid

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_SelectedIndexChang ed" 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
Nov 19 '05 #1
1 941
Hi Andy,

Since you have OnSelectedIndexChanged="ddlType_SelectedIndexChang ed", 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
el********@hotmail.com
"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_SelectedIndexChang ed" 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

Nov 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: rmorvay | last post by:
I am trying to dynamically build a dropdownlist and bind it to a cell in a grid. I tried to utilize the following code but I am stuck at the point where I bind the dropdownlist to the grid cell. ...
2
by: Dominic | last post by:
Hi guys, I'm not sure if this question belongs to FAQ, but I couldn't find a concrete answer. I created a Datagrid control using ItemTemplate, but it's NOT a in-place editing datagrid. One of...
0
by: Shane O. Pinnell | last post by:
I am sure this has come up before, but I haven't been able to find an answer as of yet. That said, any help is definitely appreciated! I have a datagrid populated from a dataset. I have a...
2
by: Shiju Poyilil | last post by:
Hello, I have a datagrid with only one row and its having 2 dropdownlists, I need to populate the secodn dropdownlist on the basis of the selection in the first dropdown. but I am not able to...
1
by: m3ckon | last post by:
Hi there, please help if you can, I'm having an issue with droponnlists in a datagrid I have a datagrid which is populated from a query .. all works fine I've added two extra columns, one...
1
by: George Durzi | last post by:
When my datagrid is in edit mode, one of my columns is edited using a drop down list. I'm able to bind the DropDownList to a DataSource when in edit mode. HOWEVER, I can't preset the...
3
by: Kenneth P | last post by:
Hi, I have a very good book on asp.net Sams ASP.NET Tips, Tutorials and Code ISBN 0-672-32143-2 and is trying to teach myself from examples from this book Chapter 16. Anyway I come quite...
3
by: Tim::.. | last post by:
Can someone please tell me how I go about preselecting an item in a drop drown list when I click the Edit Command in a datagrid? I have tried the following but it doesn't work for me! I would...
4
by: Mark Waser | last post by:
I've discovered a very odd bug when attempting to put a dropdown list in a datagrid. In the page PreRender step, the selected index of the datagrid is successfully set during databinding. Yet,...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.