try
{
KPMISDataBase dc = new KPMISDataBase();
ddlOutOrg.Properties.Columns.Clear();
var query = from o in dc.Bas_Organization
join p in dc.Fin_OrgAccount
on o.Org_ID equals p.Org_ID
where p.Acct_Status == "正常"
select new
{
o.Org_ID,
o.Org_Name
};
DataTable dt = query.Distinct ().ToDataTable(rec => new object[] { query });
if (dt.Rows.Count > 0)
{
DataRow dr = dt.NewRow();
dr["Org_ID"] = "";
dr["Org_Name"] = "--请选择--";
dt.Rows.InsertAt(dr, 0);
ddlOutOrg.Properties.Columns.Add(new LookUpColumnInfo("Org_Name"));
ddlOutOrg.Properties.ValueMember = "Org_ID";
ddlOutOrg.Properties.DisplayMember = "Org_Name";
ddlOutOrg.Properties.DataSource = dt;
ddlOutOrg.EditValue = dt.Rows[0]["Org_ID"];
}
else
{
ddlOutOrg.Properties.DataSource = null;
ddlOutOrg.Properties.NullText = "--没有数据--";
}
}
catch (Exception ex)
{
MsgBox.ErrShow(ex.Message);
}