locked
Code Behind is not executed RRS feed

  • Question

  • User594861325 posted
    I have a website that shows a dropdownlist and a gridview, the gridview is filtered by the value of the dropdownlist when i show the site in debugging mode the gridview shows the right data but when i change the value of the list nothing happens?
    but i have some code in the event of selectedindexchanged of the dropdownlist.
    Partial Public Class _Default
        Inherits System.Web.UI.Page
    
        Protected Sub DropDownList1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles DropDownList1.SelectedIndexChanged
            GridView1.DataBind()
            System.Diagnostics.Debug.WriteLine("after refresh")
        End Sub
    End Class
    
    <%@ Page Language="VB" AutoEventWireup="true" CodeFile="Default.aspx.vb" Inherits="_Default" %>
    
    <!DOCTYPE html>
    
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head runat="server">
        <title></title>
        <style type="text/css">
            #form1
            {
                width: 770px;
                margin-right: 385px;
                margin-bottom: 60px;
            }
        </style>
    </head>
    <body style="width: 1473px; height: 642px">
        <form id="form1" runat="server">
            <asp:DropDownList ID="DropDownList1" runat="server" DataSourceID="SqlDataSource2" DataTextField="Top_Rated" DataValueField="Top_Rated" Height="38px" Width="296px">
            </asp:DropDownList>
            <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:New Movie DatabaseConnectionString %>" SelectCommand="SELECT [Top Rated] AS Top_Rated FROM [TopRatedGenreQuery] ORDER BY [Top Rated]"></asp:SqlDataSource>
            <asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataSourceID="SqlDataSource1" style="margin-right: 7px" Width="697px">
                <Columns>
                    <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" />
                    <asp:BoundField DataField="Personal Rating" HeaderText="Personal Rating" SortExpression="Personal Rating" />
                    <asp:BoundField DataField="IMDB Rating" HeaderText="IMDB Rating" SortExpression="IMDB Rating" />
                </Columns>
            </asp:GridView>
            <asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:New Movie DatabaseConnectionString %>" SelectCommand="ShowTopRated" SelectCommandType="StoredProcedure">
                <SelectParameters>
                    <asp:ControlParameter ControlID="DropDownList1" DefaultValue="Action" Name="Genre" PropertyName="SelectedValue" Type="String" />
                </SelectParameters>
            </asp:SqlDataSource>
        </form>
    </body>
    </html>

    Wednesday, May 29, 2013 11:46 AM

Answers

  • User1124521738 posted

    1) add the DropDownList1_SelectedIndexChanged to the DDL: OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

    2) turn on triggers postback: AutoPostBack="True"

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 29, 2013 11:54 AM
  • User-1716253493 posted
    you need to set ddl autopostback property to true
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 29, 2013 11:56 AM

All replies

  • User1124521738 posted

    1) add the DropDownList1_SelectedIndexChanged to the DDL: OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged"

    2) turn on triggers postback: AutoPostBack="True"

    <asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" OnSelectedIndexChanged="DropDownList1_SelectedIndexChanged">
    </asp:DropDownList>




    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 29, 2013 11:54 AM
  • User-1716253493 posted
    you need to set ddl autopostback property to true
    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, May 29, 2013 11:56 AM
  • User594861325 posted

    Thanx a lot, much appreciated, it works, and many thanx for the quick reply

    Wednesday, May 29, 2013 12:12 PM