简体   繁体   English

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

[英]How to stop the dropdownlist from reverting back to default after refresh

So i have a web app that has a dropdown that is binded to a gridview, all is working perfect when i start my app and click on a different selection on the DDL.. but i have my page to refresh every 10 seconds (as needed) but for some reason once i click on a new DDL selection, after the 10 seconds the page refreshes back to the default selection. 因此,我有一个Web应用程序,该应用程序的下拉列表已绑定到gridview,当我启动我的应用程序并单击DDL上的其他选择时,一切运行正常。.但是我每10秒刷新一次页面(根据需要) ),但由于某种原因,一旦我单击新的DDL选择,则10秒钟后页面将刷新回到默认选择。 I think my issue is that my default value is in the page load so its causing the default to be refreshed each time a refresh happens, is there a way around this? 我认为我的问题是我的默认值在页面加载中,因此每次刷新时都会导致默认值被刷新,是否可以解决此问题?

Code so far... 到目前为止的代码...

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;
                    }
                }
            }
        }

The 214 is my default selection when the page opens, this updates the gridview.. But i need a solution for it to not refresh this and to keep refreshing the product i have chosen (ie i only have two selections at the moment binded to my dropdown which is 214 and 225) Anybody have any idea? 214是我在打开页面时的默认选择,这将更新gridview。。但是我需要一个解决方案,以便不刷新它并保持刷新我选择的产品(即,目前绑定到我的产品只有两个选择)下拉菜单分别是214和225)有人有什么主意吗? Thanks. 谢谢。

在您的Refreshdata方法中,请在GridView1.DataBind()之后插入以下给定的代码,让我知道它是否对您有用。

Dropdownlist1.SelectedValue=Convert.ToString(selectedProduct);

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM