List类型怎么DataSource绑定

2025-01-18 18:59:37
推荐回答(5个)
回答1:

List类型DataSource绑定代码如下:
///


/// 性别类型维护
///

public partial class SexFrm : Form
{
IList list;

private void BindData()
{
list =new SystemCodeManager().GetModelByType(type);
dgvSexType.DataSource = list;
}

private void btnAdd_Click(object sender, EventArgs e)
{
SystemCode sys = new SystemCode();
sys.CodeNo = "";
sys.EnglishName = "";
sys.ID = 12312;
sys.Name = "";
sys.QuickSign = "";
sys.Remark = "";
sys.Type = type;
list.Add(sys);

}
}

回答2:

DataSource是绑定控件必有的属性,如果你绑定数据到绑定控件中的话,你可以这样写:
先获得list数据;
绑定控件的ID.DataSource=list;
绑定控件的ID.DataBind();

当然你的前台页面必须先写好绑定该表对应的实体类中的属性

回答3:

ddl.DataSource = DateTable;
ddl.DataTextField = "Title";
ddl.DataValueField = "ID";
ddl.DataBind();

回答4:

ddl.DataSource = DateTable;
ddl.DataTextField = "Title";
ddl.DataValueField = "ID";
ddl.DataBind();
这种方法比较简捷

回答5:

List myList =new List< Entity >();
ddl.DataSource = myList;
ddl.DataTextField = "name";
ddl.DataValueField = "id";
ddl.DataBind();