Click here to Skip to main content
15,949,686 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi, i have the a combobox named cmbYear, inside the combobox have the items year eg. 2014, 2013, etc. The items are bind through data source as below:
XML
<dx:ASPxComboBox ID="cmbYear" runat="server" ClientIDMode="AutoID"
        DataSourceID="yearDataSource" ValueType="System.String"
        ValueField="Years" TextField="Years" SelectedIndex="-1">
       <Columns>
           <dx:ListBoxColumn Caption=" " FieldName="Years" />
       </Columns>
</dx:ASPxComboBox>
    <asp:SqlDataSource ID="yearDataSource" runat="server"
        ConnectionString="<%$ ConnectionStrings:vsCustomizationRequestConnectionString %>"
        SelectCommand="SELECT DISTINCT YEAR(CreateDate) AS Years FROM CRF_Project ORDER BY Years DESC">
    </asp:SqlDataSource>


and now i want to add a new item on TOP or in another word as the first item in the combobox and i use the following codes:
C#
cmbYear.Items.Insert(0, new ListEditItem("Latest"," "));

if (cmbYear.SelectedItem != null)
{
    if (cmbYear.SelectedItem.Text == "Latest")
    {
        yearsStatus = DateTime.Now.ToString("yyyy");
    }
    else
    {
        yearsStatus = cmbYear.SelectedItem.Text.TrimEnd();
    }
}
else
{
    yearsStatus = DateTime.Now.ToString("yyyy"); ;
}


but when i run my program, the new item which is "Latest" cannot be displayed inside the combobox, any idea?
Posted

1 solution

Remove the current combobox and insert a new combobox.
 
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