简体   繁体   English

如何从源连接Combobox C#中的两列

[英]how to Concatenate two Columns in Combobox C# From Source

hi i am binding a combobox from source code... now i want to concatenate it with an other database column with same table.... my source code is.... : 嗨,我从源代码绑定一个组合框...现在,我想将其与具有相同表的另一个数据库列连接起来。...我的源代码是......:

<div class="dnnFormItem">
<dnn:Label  ResourceKey="LBLEmpId" Text="Name:" runat="server" id="dlbEmpId" ControlName="ddlEmpId"  />
<asp:DropDownList ID="ddlEmpId" DataTextField="FName" DataValueField="Id" runat="server"/>
</div>

Here my "DataTextField="FName" but i want to display First name + Last name "DataTextField="FName + LName"... and my C# code is: 这里是我的“ DataTextField =“ FName”,但我想显示名字+姓氏“ DataTextField =” FName + LName“ ...,我的C#代码是:

`public void ddlEmpIdbind()
 {
  this.ddlEmpId.DataSource = new DocEmpProfile.DocEmpProfileController().GetAll(this.PortalId);
  this.ddlEmpId.DataBind();
  ListItem li = new ListItem();
  li.Text = "Select Employee";
  li.Value = "-1";
  li.Selected = true;
  this.ddlEmpId.Items.Insert(0, li);
  } `

Create a read-only property on your domain object, something like: 在您的域对象上创建一个只读属性,如下所示:

public string FullName {
    get {
        return string.format("{0} {1}", this.FName, this.LName);
    }
}

and bind that to your combobox DataTextField property. 并将其绑定到您的组合框DataTextField属性。 Consider doing this in a partial class. 考虑在局部类中进行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM