首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在刷新后阻止dropdownlist恢复为默认值

如何在刷新后阻止dropdownlist恢复为默认值
EN

Stack Overflow用户
提问于 2018-05-31 16:42:06
回答 2查看 93关注 0票数 0

因此,我有一个web应用程序,它有一个绑定到网格视图的下拉列表,当我启动我的应用程序并单击DDL上的不同选项时,一切都运行得很好。但是我的页面需要每10秒刷新一次(根据需要),但是由于某种原因,一旦我单击了新的DDL选择,在10秒之后页面就会刷新回默认选择。我想我的问题是我的默认值是在页面加载中,所以它导致每次刷新时都会刷新默认值,有什么方法可以解决这个问题吗?

到目前为止..。

代码语言:javascript
复制
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是我的默认选择,这将更新网格视图。但我需要一个解决方案,让它不刷新这一点,并不断刷新我选择的产品(即,我现在只有两个选择绑定到我的下拉列表,即214和225)。有人知道吗?谢谢。

EN

回答 2

Stack Overflow用户

发布于 2018-07-30 14:40:14

在你的刷新数据方法中,请在GridView1.DataBind()之后插入下面给定的代码,并让我知道它是否适用于你。

Dropdownlist1.SelectedValue=Convert.ToString(selectedProduct);

票数 1
EN

Stack Overflow用户

发布于 2018-05-31 17:45:18

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/50620128

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档