Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. DataBind causing infinite loop?

DataBind causing infinite loop?

Scheduled Pinned Locked Moved Database
wpfwcfdockerdebugginghelp
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    Evan Schultz
    wrote on last edited by
    #1

    I am re-writing a control I was working on to use dynamically created template columns instead of using the designer for it. For one of my columns, I need a DropDown list, this worked in my old version fine. However, when writing the Databind event for the new control I am running into a problem where when I call the DataBind() on the listcontrol, it's causing an infinite loop. It simply cuts out on the bind, and the method re-starts, I cant figure out why this is happening. However, if I simply loop though all the items in the Dataset, and add them to the dropdown list that way, this works fine - however, much rather use databinding to do this.

    private void TemplateControl_DataBindingDL(object sender,System.EventArgs e)
    {
    Debug.WriteLine("Starting DataBind:" + System.DateTime.Now);
    DropDownList lc;
    lc = (DropDownList) sender;
    string strSqlCommand;
    DataGridItem container = (DataGridItem) lc.NamingContainer;
    SqlConnection sqlConnection1 = new SqlConnection();
    DataSet dsTemp = new DataSet();
    strSqlCommand = "SELECT " + fieldName + " FROM V_T_TASKS GROUP BY " + fieldName;

    		SqlDataAdapter sqlDataAdapter1 = new SqlDataAdapter(strSqlCommand,sqlConnection1);
    		sqlConnection1.ConnectionString = "...//connection string";
    
    		sqlConnection1.Open();
    		sqlDataAdapter1.Fill(dsTemp);
    		
    		Debug.WriteLine("assigning datasource...");
    		lc.DataSource = dsTemp;
    		lc.DataTextField = fieldName;
    		lc.DataValueField = fieldName;
    		Debug.WriteLine("assignedg datasource... binding");
    		Debug.WriteLine("Rows count=" + dsTemp.Tables\[0\].Rows.Count);
    		lc.DataBind();
    		Debug.WriteLine("..bound");
    		dsTemp.Clear();
    		Debug.WriteLine("Cleared...");
    		lc.Items.Add( DataBinder.Eval(container.DataItem,fieldName,"{0}"));
    		Debug.WriteLine("Ending DataBind:" + System.DateTime.Now);
    		lc.SelectedIndex = 0;
    		sqlConnection1.Close();
    		
    	}
    

    When I run this, it'll just get to the last two debug statements, then jump back upto the start and keep looping - not throwing any errors or exceptions either. If I take out the databind and replace it with a normal loop to add each item in the dataset, it works fine. any ideas?

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups