简体   繁体   English

我如何能够在单选按钮列表的DataTextField中给出两个字符串?

[英]How i am able to give two strings in DataTextField of radiobuttonlist?

Here "name" and "specification" are fields of my tables and i want to display both that fields in the DataTextField . 这里的“名称”和“规范”是我表的字段,我想在DataTextField显示这两个字段。 I tried upper code: 我尝试了上层代码:

RadioButtonList1.DataSource = dt;
RadioButtonList1.DataTextField = "name";
RadioButtonList1.DataTextField = "specification";
RadioButtonList1.DataBind(); 

but it was not working. 但它没有用。

RadioButtonList1.Items.Clear();

foreach(var row in dt.Rows)
{
    var txt = row["name"].ToString() + " " + row["specification"].ToString();
    var val = row["id"].ToString();
    var item = new ListItem(txt,val);
    RadioButtonList1.Items.Add(item);
}

You will either need to populate the field on the item databound event or create a new combined column from dt; 您将需要填充项目数据绑定事件上的字段,或者从dt创建一个新的合并列;

var newDT = (from r in dt
             select new 
             {
                 ID = r.ID,
                 NameAndSpec = r.name + ", " + r.specification
             }
             );

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

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