2012-07-02 33 views

回答

0

所有我在Visual Studio設計編輯列第一,所以我會得到我想要的確切列。

這取決於如何將數據提取到DataGrid中。如果你使用SqlDataSource,我會建議關閉Selecting事件。在其他情況下(SqlDataReader),我會在閱讀時進行綁定。或者你也可以使用Linq to Entity來獲得你想要的值,就像這樣:

var name = from names in context.data_table 
      select names; 
gridview.datasource = name; 
0

你可以自己創建DataGridView的列。例如:

DataGridView dataGridView1 = new DataGridView(); 
BindingSource bindingSource1 = new BindingSource(); 

dataGridView1.ColumnCount = 2; 

dataGridView1.Columns[0].Name = "FieldA"; 
dataGridView1.Columns[0].DataPropertyName = "FieldA"; 
dataGridView1.Columns[1].Name = "FieldB"; 
dataGridView1.Columns[1].DataPropertyName = "FieldB"; 

bindingSource1.DataSource = GetDataTable(); 
dataGridView1.DataSource = bindingSource1; 
-1

一定要數據綁定網格設置數據源後,如上所示。祝你好運!

Entities entities = ObjectContextManager.GetCurrentContext<AdHocReportingEntities>(); 
var users = from e in entities.Users 
    where e.State == userState' 
    orderby e.Name 
    select new { e.Name, e.State}; 
Grid.DataSource = users; 
Grid.DataBind();`