【问题标题】:Bind RadcomboBox with multiple columns from Datatable将 RadcomboBox 与 Datatable 中的多列绑定
【发布时间】:2011-02-08 15:03:13
【问题描述】:

我想将 DataTable 中的“Id”、“Name”和“Email”绑定到 RadComboBox。使用 ItemTemplate 是可能的。但我不想在 RadComboBox 中显示“电子邮件”列。当 selectedIndexChanged 时,我想在标签中显示“电子邮件”。这可能吗?

谢谢你..

【问题讨论】:

  • 如果你提高你的回答率,往往会有更多的答案......

标签: asp.net telerik


【解决方案1】:

是的,您可以使用模板在 RadComboBox 中绑定这三个项目。看看这个演示:http://demos.telerik.com/aspnet-ajax/combobox/examples/functionality/templates/defaultcs.aspx

此外,要在选择项目时显示电子邮件,请设置 DataTextField="Email",这是进行选择时应显示的值。

HTH。

【讨论】:

    【解决方案2】:

    向 RadComboBox 添加自定义属性也是一个不错的选择。

        protected void RadComboBox_ItemsRequested(object sender, Telerik.Web.UI.RadComboBoxItemsRequestedEventArgs e)
        {
            try
            {
                RadComboBox myRadComboBox = (RadComboBox)sender;
    
                _rowsOfData = Db.getPeopleOfInterest();
    
                foreach (row _row in _rowsOfData)
                {
                    RadComboBoxItem item = new RadComboBoxItem
                    {
                        Text = _row.Name,
                        Value = _row.Id.ToString()
                    };
    
                    string eMail = _row.Email;
                    item.Attributes.Add("Email", Email);
                    item.DataBind();
                }
            }
            catch (Exception ex)
            {
                HandleException(ex, true);
            }
    
        }
    

    然后要在 GUI 上显示它,只需使用类似的东西:

    <td>
    <%# DataBinder.Eval(Container, "Attributes['Name']")%>
    </td>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-06
      • 1970-01-01
      • 2016-04-27
      • 1970-01-01
      相关资源
      最近更新 更多