<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True" AppendDataBoundItems="true" onselectedindexchanged="DropDownList1_SelectedIndexChanged"> <asp:ListItem>Choose one</asp:ListItem> <asp:ListItem>Price - high to low</asp:ListItem> <asp:ListItem>Price - low to high</asp:ListItem> </asp:DropDownList>
protected void Page_Load(object sender, EventArgs e) { if (Page.IsPostBack == false) { bindDropDownList(); } } protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { } private void bindDropDownList() { DropDownList1.DataSource = getReader(); DropDownList1.DataBind(); } private SqlDataReader getReader() { string strConnectionString = ConfigurationManager.ConnectionStrings["ToysConnectionString"].ConnectionString; SqlConnection myConnect = new SqlConnection(strConnectionString); string strCommandText = "SELECT package, price, description, image1, image2 FROM catalogue WHERE catalogueID <= 10 ORDER BY price desc"; SqlCommand cmd = new SqlCommand(strCommandText, myConnect); myConnect.Open(); SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection); return reader; }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { }
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e) { bindDropDownList(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)