2009-12-15 59 views
0

我有一個GridView表像這樣修改...如何在一個GridView

<div> 

    <asp:GridView ID="GridView1" runat="server" 
    AllowSorting="true" 
    OnSorting="TaskGridView_Sorting" > 
    </asp:GridView> 

</div> 

我正在填充與2周的ArrayList在GridView類似以下

DataTable taskTable = new DataTable("TaskList"); 


      taskTable.Columns.Add("File Name"); 

      taskTable.Columns.Add("Failure Count"); 

      for (int i = 0; i < namesOfFiles.Count; i++) 
      { 
       DataRow tableRow = taskTable.NewRow(); 
       tableRow["File Name"] = namesOfFiles[i]; 
       tableRow["Failure Count"] = buFailureCount[i]; 
       taskTable.Rows.Add(tableRow); 
      } 
      Session["TaskTable"] = taskTable; 

      GridView1.DataSource = Session["TaskTable"]; 
      GridView1.DataBind(); 

所以現在當我運行這個我沒有看到屏幕上的任何東西,除非我把自動生成列的屬性爲真....

有沒有一種方法,我可以得到模板字段因爲我知道很多方法來修改gridview然後,或者這些方法列在我的身後代碼..對準像現在的頭和項目使用BoundField元素停留在左邊距...

感謝

+0

你到底在問什麼? – joerage 2009-12-15 17:19:38

回答

1

是的,你可以很容易地得到模板字段。還有用於更好地控制網格視圖的元素ItemTemplateMSDN's tutorial應該給你所有你需要知道的。

有效代碼會出來這樣的事情:

<asp:GridView ID="GridView1" runat="server" AutoGenerateColumns="False" DataKeyNames="EmployeeID" DataSourceID="ObjectDataSource1"> 
    <Columns> 
     <asp:BoundField DataField="LastName" HeaderText="LastName" SortExpression="LastName" /> 
     <asp:BoundField DataField="FirstName" HeaderText="FirstName" SortExpression="FirstName" /> 
     <asp:BoundField DataField="Title" HeaderText="Title" SortExpression="Title" /> 
     <asp:BoundField DataField="HireDate" HeaderText="HireDate" SortExpression="HireDate" /> 
    </Columns> 
</asp:GridView> 

風格你網格視圖你會想看看的<RowStyle />元素。