本文介绍了如何在刷新页面后保留下拉值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在刷新后保留dropDown值Page i在下面提到代码



我尝试过:



How to dropDown Value Remain After Refresh Page i mention below Code

What I have tried:

void BindState()
   {
       DCI_Assign_Inspectors_DetailsClient client = new DCI_Assign_Inspectors_DetailsClient();
       DataSet ds = new DataSet();
       Prop objprop = new Prop();
       client.Open();
       objprop.Mode = "1";
       objprop.StateCode = "";

       try
       {
           ds = client.BindState(objprop);

           if (ds.Tables[0].Rows.Count > 0)
           {
               DrpState.DataSource = ds;
               DrpState.DataTextField = "State_Name";
               DrpState.DataValueField = "State_Code";
               DrpState.DataBind();
               DrpState.Items.Insert(0, new ListItem("--Please Select--", "All"));
           }

       }
       catch (Exception ex)
       {
           ScriptManager.RegisterStartupScript(Page, Page.GetType(), "InvalidArgs", "alert(" + ex.Message + ");", true);

       }
       finally
       {
           ds.Dispose();
           client.Close();
           objprop = null;
       }
   }

推荐答案


if(!Page.IsPostBack)
    BindState();





它将绑定第一次加载时的下拉列表和回发时函数调用不会被命中所以问题应该解决。



希望,它有帮助:)



It will bind the dropdown on first load and on postback the function call will not be hit so the issue should be resolved.

Hope, it helps :)


这篇关于如何在刷新页面后保留下拉值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

05-22 23:14