带有EF的datagrid标题中的两个单词 [英] two word in datagrid header with EF
本文介绍了带有EF的datagrid标题中的两个单词的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
嗨所有
i想在列名中使用空格来查询EF
i使用此代码并且没有问题
hi all
i want to use space in column name for query in EF
i use this code and have not problem
var q = from p1 in db.tbl_education
select new {
name = p1.edu_section
};
dgv_section.DataSource = q.ToList();
但我想要显示姓氏而不是名称
i不使用此代码:
but i want show family name instead name
i not use this code :
dgv_section.Columns["edu_section"].HeaderText = "family name";
或
or
dgv_section.Columns[1].HeaderText = "family name";
谢谢所有
thanks all
推荐答案
嗨试试这样..
Hi try like this..
var q = from p1 in db.tbl_education
select new {
family_name = p1.edu_section
};
dgv_section.DataSource = q.ToList();
谢谢
但是我说我不想用这个方法
i想要直接使用方法
谢谢
thanks
but i said that i dont want use this method
i want use a directly method
thanks
如果你没有创建一个匿名的话,可以在属性上使用DisplayNameAttribute类型。但是,你需要在DataBindingComplete事件中设置列的HeaderText属性,因为你是。
就个人而言,我认为属性方法最好,但是你必须创建一个类似于你创建匿名类型的类型。
You could use the DisplayNameAttribute on the properties if you weren't creating an anonymous type. But, you'll need to set the HeaderText property of the column in the DataBindingComplete event since you are.
Personally, I think the attribute method would be best, but you'd have to create a type that you'd create similarly to how you create the anonymous type.
class MyClass {
[DisplayName("Family Name")]
public string FamilyName { get; set; }
}
这篇关于带有EF的datagrid标题中的两个单词的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文