Click here to Skip to main content
15,881,709 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello, I created a form with data repeater and in the data repeater I have some labels and textboxes. I have binded the labels and textboxes to a dataset which is created using the following codes:

C#
<pre>private DataSet createDataSet(ProgrammingConfiguration pc)
        {
            ds = new DataSet("Preferences");

            //create a table for the preferences
            DataTable table = new DataTable("Preference");

            //Create table columns
            table.Columns.Add("Tag");
            table.Columns.Add("Precedence");
            table.Columns.Add("DataType");
            table.Columns.Add("Length");
            table.Columns.Add("Value");
            table.Columns.Add("Maximum");
            table.Columns.Add("Minimum");
            table.Columns.Add("OverflowBehaviour");

            //Load object data to dataset
            for (int i = 0; i < pc.Preferences.Length; i++)
            {
                if (pc.Preferences[i].Value.ItemElementName == ItemChoiceType.AutoIncrement)
                {
                    ValueTypeAutoIncrement incrementalData = (ValueTypeAutoIncrement)pc.Preferences[i].Value.Item;
                    table.Rows.Add(pc.Preferences[i].Tag, pc.Preferences[i].Precedence, pc.Preferences[i].Value.ItemElementName, pc.Preferences[i].Value.Length,
                        "", incrementalData.Maximum, incrementalData.Minimum, incrementalData.OverflowBehaviour);
                }
                else
                {
                    table.Rows.Add(pc.Preferences[i].Tag, pc.Preferences[i].Precedence, pc.Preferences[i].Value.ItemElementName, pc.Preferences[i].Value.Length, pc.Preferences[i].Value.Item);
                }
            }

            //Add to dataset
            ds.Tables.Add(table);  
                  
            return ds;
        }



I bind the controls with the following methods:

C#
private void bindControls()
       {
           //Define binding source
           bindingsource = new BindingSource();
           bindingsource.DataSource = ds;

           //clear before binding
           TagLabel.DataBindings.Clear();
           PrecedenceLabel.DataBindings.Clear();
           DataTypeLabel.DataBindings.Clear();
           LengthLabel.DataBindings.Clear();
           ValueTextBox.DataBindings.Clear();
           MaxTextBox.DataBindings.Clear();
           MinTextBox.DataBindings.Clear();
           OverflowComboBox.DataBindings.Clear();

           //Bind controls (This has to be done before binding datarepeater)
           TagLabel.DataBindings.Add(new Binding("Text", bindingsource, "Tag"));
           PrecedenceLabel.DataBindings.Add(new Binding("Text", bindingsource, "Precedence"));
           DataTypeLabel.DataBindings.Add(new Binding("Text", bindingsource, "DataType"));
           LengthLabel.DataBindings.Add(new Binding("Text", bindingsource, "Length"));
           ValueTextBox.DataBindings.Add(new Binding("Text", bindingsource, "Value", false, DataSourceUpdateMode.OnPropertyChanged));
           MaxTextBox.DataBindings.Add(new Binding("Text", bindingsource, "Maximum", false, DataSourceUpdateMode.OnValidation));
           MinTextBox.DataBindings.Add(new Binding("Text", bindingsource, "Minimum", false, DataSourceUpdateMode.OnValidation));
           OverflowComboBox.DataBindings.Add(new Binding("SelectedItem", bindingsource, "OverflowBehaviour", false, DataSourceUpdateMode.OnPropertyChanged));


           //Bind data repeater
           dataRepeater.DataSource = bindingsource;
           dataRepeater.DataMember = "Preference";
       }



I want to edit the ValueTextBox and change its value. However, as soon as I leave the textbox, the value is reset back to its original value. I pressume the dataset is not updated with the new value. Can anyone suggest how to achieve updating the dataset when textbox is updated please?
Posted

1 solution

Hi,

Maybe because you have PostBack.
Try to use the the update pannel with Update mode equal "Conditional" to hide the pannel value when postback.

In your client code:
   <asp:updatepanel id="panelToUpdate" runat="server" updatemode="Conditional" xmlns:asp="#unknown">
   

</asp:updatepanel>


In your code behind:
C#
panelToUpdate.Update();


Regards,
 
Share this answer
 
Comments
YHiew 11-Oct-12 4:24am    
Hi, thanks for the suggestion. I am not developing a web form, so i m not using ASP. This is a windows form.

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