This is a migrated thread and some comments may be shown as answers.

Repopulating data on button click

2 Answers 19 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Nicklas
Top achievements
Rank 1
Nicklas asked on 06 Aug 2013, 03:06 PM
Hi!

I am populating my data in my RadComboBox by using a ObjectDataSource, everything works fine.

Now when I want to delete items from the RadCombobox and the database it doesnt work. 

It gets removed from the database successfully, but it still remains in my combobox, even though I refresh the page it still remains, The only thing that works is to shutdown the whole debugging and start it again, then it repopulates the data from the database.

Any idea what to do to repopulate the data? Ive tried doing a full post back, with no luck. I have searched forum and tried several propsals with no luck.

I am starting to think its because its saved in cached or in memory somehow? (clientsided)

Appreciate any help!

2 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 1
answered on 07 Aug 2013, 04:35 AM
Hi Nicklas,

Please have a look at the following C# code snippet that I tried for deleting items from both RadComboBox and database.

C#:
protected void RadButton1_Click(object sender, EventArgs e)
{
    RadComboBox1.ClearSelection();
    RadComboBox1.Items.Clear();
    String  connstring = WebConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString;
    SqlConnection connection = new SqlConnection(connstring);
    string sqlStatement = "DELETE FROM City";
    try
    {
        connection.Open();
        SqlCommand cmd = new SqlCommand(sqlStatement, connection);
        cmd.CommandType = CommandType.Text;
        cmd.ExecuteNonQuery();
    }
    finally
    {
        connection.Close();
    }
}

Thanks
Shinu.
0
Nicklas
Top achievements
Rank 1
answered on 07 Aug 2013, 01:33 PM
Did some changes and managed to get it to work, I now populate my data by using 2 comboboxes, the latter is filtered by the first, by adding a event listener on the first combobox, so whenever something is changed in the first combobox, the latter combobox will get filtered.

protected void ComboBox_SelectedIndexChanged(object sender, RadComboBoxSelectedIndexChangedEventArgs e)
 
 
            ComboBox.DataSource = //dataset here / datatable
            ComboBox.DataTextField = "column you wish to show in combobox";
            ComboBox.DataBind();
 
//Then Finally clearing the combobox text or as in my case I decided to select the first item in the dataset instead.
 
ComboBox.Items[0].Selected = true;
}
Tags
ComboBox
Asked by
Nicklas
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 1
Nicklas
Top achievements
Rank 1
Share this question
or