Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi all
i want to use space in column name for query in EF
i use this code and have not problem
C#
var q = from p1 in db.tbl_education
                    select new {  
          name  =  p1.edu_section   
                    
                    };
            dgv_section.DataSource = q.ToList();

but i want show family name instead name

i not use this code :
C#
dgv_section.Columns["edu_section"].HeaderText = "family name";

or
C#
dgv_section.Columns[1].HeaderText = "family name";

thanks all
Posted
Comments
Karthik_Mahalingam 3-Dec-13 10:25am    
try my solution now..

Hi try like this..


C#
var q = from p1 in db.tbl_education
                    select new {
          family_name =  p1.edu_section

                    };
            dgv_section.DataSource = q.ToList();
 
Share this answer
 
v2
Comments
Karthik_Mahalingam 3-Dec-13 10:27am    
you cannot define white spaces for an anonymous property name, u can add underscore "_" instead...
saleh aghaee 3-Dec-13 10:45am    
that is right but i dont want use _
is there a character instead _ or spase that not shown?
Karthik_Mahalingam 3-Dec-13 11:24am    
no such character is there ..
thanks
but i said that i dont want use this method
i want use a directly method
thanks
 
Share this answer
 
Comments
Karthik_Mahalingam 3-Dec-13 10:21am    
use " have a question or comment " button to add comments or ask doubts ...
dont use solution block...
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.

C#
class MyClass {
   [DisplayName("Family Name")]
   public string FamilyName { get; set; }
}
 
Share this answer
 
that is right but i dont want use _
is there a character instead _ or space that not shown?
 
Share this answer
 
solution for this issue

C#
private void dgv_log_ColumnAdded(object sender, DataGridViewColumnEventArgs e)
       {
           foreach (DataGridViewColumn element in dgv_log.Columns)
           {
               element.HeaderText = element.HeaderText.Replace("_", " ");
           }
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900