如何在刷新后停止下拉列表恢复为默认值

时间:2018-05-31 08:42:06

标签: c# asp.net dropdown

所以我有一个网页应用程序,其下拉列表绑定到gridview,当我启动我的应用程序并点击DDL上的其他选项时,一切都工作正常..但我的页面每隔10秒刷新一次(根据需要)但由于某种原因,一旦我点击新的DDL选择,在10秒后页面刷新回默认选择。我认为我的问题是我的默认值是在页面加载中,因此每次刷新时都会刷新默认值,有没有办法解决这个问题?

到目前为止

代码......

protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                Refreshdata(214, DateTime.Today, DateTime.Today.AddDays(1).AddMinutes(-1));
                BindDropDownList();



            }
        }

        private void BindDropDownList()
        {
            BizManager mgr = new BizManager();

            DataView dv = mgr.GetItemSeriesMaster().DefaultView; //how to filter data
            dv.RowFilter = ProductQueryFilter;
            Dropdownlist1.DataSource = dv;
            Dropdownlist1.DataTextField = "Description"; // the items to be displayed in the list items
            Dropdownlist1.DataValueField = "Id"; // the id of the items displayed
            Dropdownlist1.DataBind();

        }

        private string ProductQueryFilter
        {
            get { return ConfigurationManager.AppSettings["ProductQueryFilter"]; } //returns itemseriesmaster 214 or 225
        }


        public void Refreshdata(int selectedProduct, DateTime shiftStart, DateTime shiftEnd)
        {
            BizManager biz = new BizManager();

            GridView1.DataSource = biz.GetPacktstatisticsForShift(
                shiftStart
                , shiftEnd
                , selectedProduct).DefaultView;
            GridView1.DataBind();
        }

        public void Dropdownlist1_SelectedIndexChanged(object sender, EventArgs e)
        {
            DateTime shiftStart = DateTime.Today;
            DateTime shiftEnd = DateTime.Today.AddDays(1).AddMinutes(-1);
            int productId;
            if (int.TryParse(Dropdownlist1.SelectedValue, out productId))
                Refreshdata(productId, shiftStart, shiftEnd);
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                //if (e.Row.Cells[2].Text.Trim() == "0")
                //    e.Row.Cells[2].ForeColor = System.Drawing.Color.Red;
                //if (e.Row.Cells[4].Text.Trim() == "0")
                //    e.Row.Cells[4].ForeColor = System.Drawing.Color.Red; ~~~these find a specific number to change i.e change all 0 to green.
                //if (e.Row.Cells[6].Text.Trim() == "0")
                //    e.Row.Cells[6].ForeColor = System.Drawing.Color.Red;

                for (int i = 0; i < e.Row.Cells.Count; i++)
                {
                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[1].ForeColor = Color.Red;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[3].ForeColor = Color.Red;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[5].ForeColor = Color.Red;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[7].ForeColor = Color.Red;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[2].ForeColor = Color.Black;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[4].ForeColor = Color.Black;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[6].ForeColor = Color.Black;
                    }

                    if (e.Row.Cells[i].Text.ToLower().IndexOf("0") > -1)
                    {
                        e.Row.Cells[8].ForeColor = Color.Black;
                    }
                }
            }
        }

当页面打开时,214是我的默认选择,这会更新gridview ..但我需要一个解决方案,不刷新它并保持刷新我选择的产品(即我目前只有两个选择绑定到我的下拉列表214和225)任何人有任何想法?感谢。

2 个答案:

答案 0 :(得分:1)

在您的Refreshdata方法中,请在Resolved exception caused by Handler execution: org.springframework.web.bind.MissingServletRequestParameterException: Required String parameter 'paramSelect' is not present 之后插入以下给定的代码,让我知道它是否对您有用。

GridView1.DataBind()

答案 1 :(得分:0)

在刷新代码中,包含DropdownList选择值作为参数,并在BindDropDownList()方法中选择相同的值。