Click here to Skip to main content
15,898,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello guys,

I want to refresh dropdownlist data source in asp.net when data is changed in source table.


I am using popup window to add new entry in table and entry is submited success fully. but when I close the popup window data in dropdownlist remains same. New value doesnot displaying in drop down list.

and if I refresh page then data entered in previous textboxes is removed and I need to re enter all data.

Please help me...

Thanx in advance....
Posted
Comments
RelicV 28-May-13 8:16am    
It depends on your code actually. Are you using any Cache? Please provide the code..

try this:

protected void Page_Load(object sender, EventArgs e)
   {
        if (!IsPostBack)
       {
           string str = ConfigurationManager.ConnectionStrings["Class28ConnectionString"].ToString();
           SqlConnection con = new SqlConnection(str);
           string sql = "select * from t_c";
           SqlCommand cmd = new SqlCommand(sql, con);
           con.Open();

           SqlDataReader rdr = cmd.ExecuteReader();
           while (rdr.Read())
           {
               ListItem lst = new ListItem();
               lst.Text = rdr[1].ToString();
               lst.Value = rdr[0].ToString();
               DropDownList1.Items.Add(lst);
           }
           DropDownList1.DataSource = rdr;
           DropDownList1.Items.Insert(0, new ListItem("select", "0"));

       }
   }
 
Share this answer
 
v2
Refresh the parent page from popup window, 
Then Bind the dropdownlist items on !is post back.

protected void Page_Load(object sender, EventArgs e)
    {
         if (!IsPostBack)
        {
SqlConnection con = new SqlConnection("Data Source=;Database=;User ID=;Password=!;Asynchronous Processing=true");
con.Open();
            SqlCommand cmd = new SqlCommand("select firstname from contacts", con);
            SqlDataAdapter dtAdapter = new SqlDataAdapter(cmd);
            DataTable dt= new DataTable();
            dtAdapter.Fill(dt);
            ddl1.DataSource = dt;
            ddl1.DataTextField = "firstName";
            ddl1.DataValueField = "firstName";
            ddl1.DataBind();
            ddl1.Items.Insert(0, new ListItem("select", "0"));
         }
    }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900