将项目添加到组合框中
我有一个名为cmbYear的组合框,在组合框中有项目年份,例如。通过以下数据源绑定项目:
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:
<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>
和现在我想在TOP或另一个单词中添加一个新项目作为组合框中的第一项,我使用以下代码:
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:
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?
ConnectionStrings:vsCustomizationRequestConnectionString %>
SelectCommand = SELECT DISTINCT YEAR(CreateDate)AS CRF_Project的年份ORDER BY DESC >
< / asp:SqlDataSource >
ConnectionStrings:vsCustomizationRequestConnectionString %>" SelectCommand="SELECT DISTINCT YEAR(CreateDate) AS Years FROM CRF_Project ORDER BY Years DESC"> </asp:SqlDataSource>
现在我想在TOP或另一个单词中添加一个新项目作为组合框中的第一项,我使用以下代码:
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:
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?
删除当前的组合框并插入一个新的组合框。
Remove the current combobox and insert a new combobox.