Search code examples
asp.netitemtemplate

OnSelectedIndexChanged on a GridView's ItemTemplate not firing


I have a GridView with some ItemTemplate and I need to work with the SelectedIndexChanged event... I manually wrote the codes but it's not working... Check it out:

HTML code:

<asp:TemplateField HeaderText="PROJETO" HeaderStyle-Width="90px" ItemStyle-HorizontalAlign="Center" ItemStyle-Font-Size="12px">
      <ItemTemplate>
          <asp:DropDownList ID="Drop_Projetos" Width="115px" runat="server" OnSelectedIndexChanged="Drop_Projetos_SelectedIndexChanged" EnableViewState="false"
          AutoPostBack="true"></asp:DropDownList>
      </ItemTemplate>
</asp:TemplateField>

And here's my codebehind, where I've put a breakpoint but it isn't even fired...

protected void Drop_Projetos_SelectedIndexChanged(object sender, EventArgs e)
        {
           //SomeCode
        }

Solution

  • You have to add to the DropDownList:

    AutoPostBack="true"
    

    Then it will post back to the server.