开发者

Dropdown list selected index changed

开发者 https://www.devze.com 2022-12-27 03:39 出处:网络
I did my drop down list that get its values from the database and when running the application, it did not work and the compiler did not see the code.

I did my drop down list that get its values from the database and when running the application, it did not work and the compiler did not see the code.

// aspx

  <asp:UpdatePanel ID="UpdatePanel3" runat="server">
                 <ContentTemplate>
                       <asp:DropDownList ID="DDlProductFamily" runat="server"
                         ondatabound="DDlProductFamily_DataBound"
                         onselectedindexchanged="DDlProductFamily_SelectedIndexChanged">
                                                </asp:DropDownList>
                                            </ContentTemplate>
                                            <Triggers>
                                                <asp:AsyncPostBackTrigger ControlID="DDlProductFami开发者_Go百科ly" EventName="SelectedIndexChanged" />
                                            </Triggers>
                                        </asp:UpdatePanel>

// cs

 protected void DDlProductFamily_SelectedIndexChanged(object sender, EventArgs e)
    {
        using (SqlConnection Con = Connection.GetConnection())
        {
            SqlCommand Com = new SqlCommand("SelectThumbByProductFamily", Con);
            Com.CommandType = CommandType.StoredProcedure;
            Com.Parameters.Add(Parameter.NewInt("@ProductCategory_Id",
                DDlProductFamily.SelectedValue.ToString()));
            SqlDataAdapter DA = new SqlDataAdapter(Com);
            DA.Fill(dt);
            DataList1.DataSource = dt;
            DataList1.DataBind();
        }
    }


Check if listbox has property AutoPostBack="True".


You need to be loading the DLL data on, for example, Page Load, it is empty so your DDL will never have its SelectedIndex changed.

You need to do something like this psuedo code:

Page_load
{
   if(!IsPostBack)
   {
       BindData();

   }
}

BindData()
{
     // Do your DataBase/whatever call to fill the DDL


}

And your code for protected void DDlProductFamily_SelectedIndexChanged(object sender, EventArgs e) stays the same.

Your DDL will also need the property AutoPostBack="true"


Do you have AutoEventWireup="true" set in the page directive at the top of your ASPX page? You will need this setting set to true in order for your code to work.

For more information please see Information about the AutoEventWireup attribute:

In Visual Studio .NET or in Visual Studio 2005, events are bound to event-handler methods using event delegates. If you use the Web Forms Designer to design Web Forms, the designer automatically generates code to bind events to their event-handler methods.

0

精彩评论

暂无评论...
验证码 换一张
取 消