Hi I am trying to rebind data to a DataList that get’s it’s data from an SqlDataSource but I keep getting duplicate items. Here is my code:
<asp:SqlDataSource ID="CategoryDataSource" runat="server"
ConnectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\ASPNETDB.MDF;Integrated Security=True;User Instance=True"
ProviderName="System.Data.SqlClient" SelectCommand="SELECT [CategoryName] FROM [forum_categories]">
</asp:SqlDataSource>
protected void Button6_Click( object sender , EventArgs e )
{
string categoryToCreate = CreateCategory.Text;
if(categoryToCreate != string.Empty)
{
CategoryCreateName.Visible = false;
DataAccess.insertDataItem(categoryToCreate);
CategoryList.DataBind();
}
else
{
CategoryCreateName.Visible = true;
}
}
The insertDataItem inserts a new category into the database.
How can I update the items in the DropDownList so that I do not get duplicate items?
Try This: