How do I bind a ComboBox so the displaymember is concat of 2 fields of source datatable?

后端 未结 7 2003
既然无缘
既然无缘 2020-12-01 18:03

I\'d like to bind a ComboBox to a DataTable (I cannot alter its original schema)

cbo.DataSource = tbldata;
cbo.DataTextField = \"Na         


        
7条回答
  •  悲&欢浪女
    2020-12-01 18:35

    I would create a property on your data object then map that to the DataTextField

    Data Object

    public string FullName
    {
      get { return Name + " " + Surname; }
    }
    

    Code-behind

    cbo.DataSource = tbldata;
    cbo.DataTextField = "FullName";
    cbo.DataValueField = "GUID";
    cbo.DataBind();
    

提交回复
热议问题