1

这里“名称”和“规格”是我的表格的字段,我想在DataTextField. 我尝试了上面的代码:

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

但它不起作用。

4

2 回答 2

1
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);
}
于 2013-03-06T19:08:36.943 回答
1

您将需要填充项目数据绑定事件的字段或从 dt 创建一个新的组合列;

var newDT = (from r in dt
             select new 
             {
                 ID = r.ID,
                 NameAndSpec = r.name + ", " + r.specification
             }
             );
于 2013-03-06T19:08:48.610 回答