Вопрос

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
        }
Это было полезно?

Решение

You have to add to the DropDownList:

AutoPostBack="true"

Then it will post back to the server.

Другие советы

Missing autopostback in the drop down list AutoPostBack="true"

<asp:DropDownList ID="Drop_Projetos" Width="115px" runat="server"  AutoPostBack="true"
 OnSelectedIndexChanged="Drop_Projetos_SelectedIndexChanged" EnableViewState="false">    
        </asp:DropDownList>

Edit 1

Here is a similar question which may help you
How can I add cascading drop downs inside of a gridview for edits?
Implementing cascading DropDownList binding in a templated control

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top