将项目添加到组合框中 [英] Add an item into combobox

查看:159
本文介绍了将项目添加到组合框中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个名为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.


这篇关于将项目添加到组合框中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆