Trying to wire up dropdownlist in datagrid

Discussion in 'ASP .Net' started by Andy Sutorius via DotNetMonster.com, Jun 10, 2005.

  1. 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
     
    Andy Sutorius via DotNetMonster.com, Jun 10, 2005
    #1
    1. Advertising

  2. 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



    "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
    >
     
    =?Utf-8?B?RWx0b24gVw==?=, Jun 10, 2005
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Anand P. Paralkar

    Wire Load Models

    Anand P. Paralkar, Apr 22, 2004, in forum: VHDL
    Replies:
    5
    Views:
    6,219
  2. mohammed rafi
    Replies:
    3
    Views:
    14,725
    Charles Bailey
    May 7, 2004
  3. Alex
    Replies:
    2
    Views:
    1,989
  4. AMT2K5
    Replies:
    0
    Views:
    376
    AMT2K5
    Mar 6, 2007
  5. David
    Replies:
    5
    Views:
    286
    Jeffrey Tan[MSFT]
    Feb 18, 2004
Loading...

Share This Page