Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 3 dropdown list. when i select brand dropdownlist. it fill the records in Product dropdownlist as well it display sales records based on Brand. but i want sale records should fill only when user click on Submit button.


View :

HTML
@model withoutModelEdmx.Models.masterList

@{
    ViewBag.Title = "dropdownlist bind demo with model";  
}
@using (Html.BeginForm("postyourad", "stok", FormMethod.Post, new { id = "TheForm" }))
 {
    @Html.DropDownListFor(x => x._brand, Model.getBrand(), "--Choose Your Brand--",
    new
    {
        onchange = "document.getElementById('TheForm').submit();"
    })
    @Html.DropDownListFor(x => x._product, Model.getProduct(), "--Choose Your Product--",
    new
    {
        onchange = "document.getElementById('TheForm').submit();"
    })
    @Html.DropDownListFor(x => x._model, Model.getModel(), "--Choose Your Model--",
    new
    {
       onchange = "document.getElementById('TheForm').submit();"
    }    )
       
   <input type="submit" value="submit"  />
   
    @foreach (var list in Model.GetSaleRecords())
    { 
        
    }
     
            
              @list.Id
                      
            <input value="@list.bill_amt" type="text" class="data1" />
            
            @list.brand
            
            @list.product
            
            <input value="@list.price" type="text" class="data1" />
            
            @list.Qty
            
          
 }



Contoller:
C#
[HttpGet]
    public ActionResult postyourad()
    {
        return View(new masterList());
    }
    [HttpPost]
    public ActionResult postyourad(masterList ddlListPostData)
    {
        return View(ddlListPostData);
    }



Model:
C#
public class masterList
    {

        [Required]
        public virtual string _model { get; set; }
        [Required]
        public virtual string _product { get; set; }
        [Required]
        public virtual string _brand { get; set; }

        public IList<SelectListItem> mastr_name { get; set; }
        ConnectionClass con_cs = new ConnectionClass();
        public SelectList getBrand()
        {
            IEnumerable<SelectListItem> BrandList = (from s in con_cs.stock_entries                                                   
                                                     select new SelectListItem()
                                                     {
                                                         Text = s.brand,
                                                         Value = s.brand
                                                     }).Distinct().OrderBy(x => x).ToList<SelectListItem>();
            return new SelectList(BrandList, "Value", "Text", _brand);
        }
        public SelectList getProduct()
        {
            IEnumerable<SelectListItem> ProductList = new List<SelectListItem>();
            if (!string.IsNullOrEmpty(_brand))
            {
                ProductList = (from s in con_cs.stock_entries
                               where s.brand == _brand
                               select new SelectListItem()
                               {
                                   Text = s.product,
                                   Value = s.product
                               }).Distinct().ToList<SelectListItem>();
            }
            return new SelectList(ProductList, "Value", "Text", _product);
        }        
        public SelectList getModel()
        {
            IEnumerable<SelectListItem> ModelList = new List<SelectListItem>();
            if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product))
            {
                ModelList = (from s in con_cs.stock_entries
                             orderby s.model
                             where s.brand == _brand && s.product== _product
                             select new SelectListItem()
                             {
                                 Text = s.model,
                                 Value = s.model
                             }).Distinct().ToList<SelectListItem>();
            }
            return new SelectList(ModelList, "Value", "Text", _model);
        }
        public List GetSaleRecords()
        {
            List query = new List();          
            if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product) && !string.IsNullOrEmpty(_model))            
            {

                query = (from pd in con_cs.SaleDtls_entries
                         join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
                         where pd.brand == _brand && pd.product == _product && pd.model_no == _model
                         orderby od.Id
                         select new Mydata
                         {
                             Id = od.Id,
                             req_no = od.req_no,
                             product = pd.product,
                             brand = pd.brand,
                             price = pd.price,
                             Qty = pd.Qty,
                             bill_amt = od.bill_amt,
                         }).ToList();
            }
            else
            {
                if (!string.IsNullOrEmpty(_brand) && !string.IsNullOrEmpty(_product))
                {
                    query = (from pd in con_cs.SaleDtls_entries
                             join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
                             where pd.brand == _brand && pd.product == _product
                             orderby od.Id
                             select new Mydata
                             {
                                 Id = od.Id,
                                 req_no = od.req_no,
                                 product = pd.product,
                                 brand = pd.brand,
                                 price = pd.price,
                                 Qty = pd.Qty,
                                 bill_amt = od.bill_amt,
                             }).ToList();
                }
                else
                {
                    if (!string.IsNullOrEmpty(_brand))
                    {
                        query = (from pd in con_cs.SaleDtls_entries
                                 join od in con_cs.SaleMstr_entries on pd.req_no equals od.req_no
                                 where pd.brand == _brand
                                 orderby od.Id
                                 select new Mydata
                                 {
                                     Id = od.Id,
                                     req_no = od.req_no,
                                     product = pd.product,
                                     brand = pd.brand,
                                     price = pd.price,
                                     Qty = pd.Qty,
                                     bill_amt = od.bill_amt,
                                 }).ToList();
                    }
                }
            }
            return query;
        }
    }
Posted
Updated 2-Feb-14 21:48pm
v3

1 solution

Now for each 3 drop down list there is"OnClick" event associated that automatically submit your form (simulating press on submit button). So you have to change these java script code and you could for example use jQuery and AJAX to fill only the drop down list and not to submit the entire page.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900