Link to home
Start Free TrialLog in
Avatar of Aravind Ranganathan
Aravind Ranganathan

asked on

dropdownlist does not retain values after communicating with masterpage

i have a filter option in a table

User generated image
so the filter works

User generated image
but when i click the edit icon on the right then it hits the master page and does a postback and reloads the dropdownlist vales again that resets it back to selected index = 0, how can i avoid this postback to retain the filter values?

so this is how i initally populate the dropdown list on page_load

 if (amiadmin == "YES" || amiadmin == "NO")
                    {
                        if (!IsPostBack)
                        {
                            headervaluess.Items.Clear();
                            for (int i = 0; i < GridView1s.Columns.Count; i++)
                            {
                                if (GridView1s.Columns[i].HeaderText != "MultipleApproval" && GridView1s.Columns[i].HeaderText != "" && GridView1s.Columns[i].HeaderText != "Date" && GridView1s.Columns[i].HeaderText != "TimeStamp" && GridView1s.Columns[i].HeaderText != "Explanation_Details")
                                {
                                    if (GridView1s.Columns[i].HeaderText == "Item Code")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("Item Code", "Item_Code"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "Item Description")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("Item Description", "Item_Desc"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "FirstQual")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("FirstQual", "[1st_Quality]"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "uncoated")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("uncoated", "Un_coated_rework"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "coatedrework")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("coatedrework", "CoatedRework"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "purgeout")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("purgeout", "Purge_Out_UC_Rework"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "FloorWaste")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("FloorWaste", "Floor_Waste"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "MachineWaste")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("MachineWaste", "Machine_Waste"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "purgeouts")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("purgeouts", "Purge_Out"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "rsw")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("rsw", "Roller_Scraper_Waste"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "EW")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("EW", "Extraordinary_Waste"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "NoFCR")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("NoFCR", "NOFCR"));
                                    }
                                    else if (GridView1s.Columns[i].HeaderText == "ActualWasteShipments")
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText.Replace("ActualWasteShipments", "[Actual_Waste_Shipment]"));
                                    }
                                    else
                                    {
                                        headervaluess.Items.Add(GridView1s.Columns[i].HeaderText);
                                    }
                                }
                                else
                                {

                                }

                            }
                        }//AvailableLinesQuery = "SELECT TOP (100) PERCENT Line FROM dbo.General WITH (nolock) WHERE  ((VStatus < 2) AND (plant = @Plant) and  (DateEntered >= @DDate) and (WhichMenuItem = @WhichMenuItem)) OR   ((VStatus = 0) AND (Plant = @Plant) AND (WhichMenuItem = @WhichMenuItem)) GROUP BY Line";
                        //AvailableMachinesQuery = "SELECT TOP (100) PERCENT Machine FROM dbo.General WITH (nolock) WHERE  ((VStatus < 2) AND (plant = @Plant) and  (DateEntered >= @DDate) and (WhichMenuItem = @WhichMenuItem)) OR   ((VStatus = 0) AND (Plant = @Plant) AND (WhichMenuItem = @WhichMenuItem)) GROUP BY Machine";
                       // headervaluess.Items.Insert(0, new ListItem(String.Empty, String.Empty));
                        //headervaluess.SelectedIndex = 0;
                    }

Open in new window


the above code should only run initially when its not postback because i want the drop down list to retain the values but what happens is  the content page goes to Master page and when it returns back to content page again it runs the page load as non postback runs populating the drop downlist values. <- this happens when i click on the edit button.

any help is appreciated.

Thanks
Avatar of Kyle Abrahams, PMP
Kyle Abrahams, PMP
Flag of United States of America image

Best way would be to ajax the postback and only refresh the gridview.
https://www.aspsnippets.com/Articles/GridView---Add-Edit-Update-Delete-and-Paging-the-AJAX-way.aspx
This question needs an answer!
Become an EE member today
7 DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform.
View membership options
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.