0

I select one value on the ddl , and it does not show the products in the page. The selected value remains binded but the page is blank.

Also , if I just call function getCat() without using if(!ispostback). When i load the page the drop down list is stuck on the first value , but it shows the products in page.

Drop Down List:

<asp:dropdownlist runat="server" id="ddcateg" AutoPostBack="true" onselectedindexchanged="Ddcateg_SelectedIndexChanged"></asp:dropdownlist>

This is the implementation:

protected void Page_Load(object sender, EventArgs e)
{
    //afisare();

    if (!IsPostBack)
    {
        getCateg();
    }

}


public void getCateg()
{

    ProdusTipModel model = new ProdusTipModel();
    FarmacieEntities db = new FarmacieEntities();

    var lizt = (from c in db.ProdusTips select c).ToList();


        ddcateg.DataSource = lizt;
        ddcateg.DataValueField = "ID";
        ddcateg.DataTextField = "Name";


    ddcateg.DataBind();
    ddcateg.SelectedIndexChanged += Ddcateg_SelectedIndexChanged;
}


public void afisare2(List<Produ> z)
{
    ProdusModel mdl = new ProdusModel();

        foreach (var produs in z)
        {
            Panel produsePnl = new Panel();
            ImageButton imageButton = new ImageButton();
            produsePnl.BorderColor = Color.AliceBlue;

            Label lblNume = new Label();
            Label lblPret = new Label();

            produsePnl.BorderStyle = BorderStyle.Groove;
            produsePnl.BorderColor = Color.LightSkyBlue;

            imageButton.ImageUrl = "~/Img/Produse/" + produs.Image;
            imageButton.CssClass = "imgProdus";
            imageButton.PostBackUrl = "~/Pages/PaginaProdus.aspx?id=" + produs.ID;

            lblNume.Text = produs.Name;
            lblNume.CssClass = "numeProd";

            lblPret.Text = produs.Price + "lei";
            lblPret.CssClass = "produsPret";


            produsePnl.Controls.Add(imageButton);
            produsePnl.Controls.Add(new Literal { Text = "<br /" });
            produsePnl.Controls.Add(lblNume);
            produsePnl.Controls.Add(new Literal { Text = "<br /" });
            produsePnl.Controls.Add(lblPret);

            pnlProduse.Controls.Add(produsePnl);

        }

}



private void Ddcateg_SelectedIndexChanged(object sender, EventArgs e)
{
   DropDownList selectedList = (DropDownList)sender;
   int selectedLit = Convert.ToInt32(selectedList.SelectedValue);

   ProdusModel mdl = new ProdusModel();
   List<Produ> list = mdl.GetProdCateg(selectedLit).ToList();

   afisare2(list);

}
3
  • you misspelled the event name: it is onselectedindexchanged, not onselectedindexchange Commented Dec 31, 2017 at 10:53
  • that i wrote myself , in my code is correctly , it doesnt work :( Commented Dec 31, 2017 at 10:58
  • please always post the code that you're actually using. provide a minimal, complete example so people could reproduce the problem. Commented Dec 31, 2017 at 11:00

1 Answer 1

1

Your problem could be that your code behind method is private:

private void Ddcateg_SelectedIndexChanged(object sender, EventArgs e)

Try making it protected or public so it can be seen by the aspx page.

Sign up to request clarification or add additional context in comments.

3 Comments

I totally forgot about it , it was automatically generated . That was the problem. Thank you !
If it cannot be seen by the aspx you should get method not found exception
I use visual studio. Sometimes the error field does't show me all the errors .I have to complie 2-3 times to get it diplayed. Akward , only to me i'ts happening. Thank you again for the answer :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.