2010-03-05 36 views
2

全部。我有一個問題讓GridView.AutoGenerateEditButton屬性爲我做任何事情。現在,我將它設置爲true,並且我甚至沒有將按鈕添加到我的GridView中,顯然,我甚至無法進一步編寫實際事件。以下是我迄今爲止(抱歉亂碼,我越來越接近我的最後期限,它是一個有點瘋狂的):C#Gridview:設置AutoGenerateEditButton

SqlDataAdapter da = new SqlDataAdapter(); 
da.SelectCommand = cmd; 
using(SqlDataReader dr = cmd.ExecuteReader()) 
{ 
    DataSet ds1 = new DataSet(); 
    DataTable dt1 = ds1.Tables.Add("Specs 1"); 
    if (dt1.Rows.Count == 0) 
    { 
     ds1.Tables["Specs 1"].Columns.Add("General Information"); 
     ds1.Tables["Specs 1"].Columns.Add("Customer Name"); 
     ds1.Tables["Specs 1"].Columns.Add("Address"); 
     // etc. 
    } 
    while (dr.Read()) 
    { 
     DataRow newRow = ds1.Tables["Specs 1"].NewRow(); 
     int x = 0; 
     foreach (DataColumn thisColumn in ds1.Tables["Specs 1"].Columns) 
     { 
      newRow[ds1.Tables["Specs 1"].Columns[x]] = Convert.ToString(dr[x]); 
      x += 1; 
     } 
     ds1.Tables["Specs 1"].Rows.Add(newRow); 
    } 
    DataSet flipped_ds1 = FlipDataSet(ds1); // Flips the dataset's orientation. 

然後,當它的時間對我來說,GridView控件添加到頁面,我使用以下代碼:

GridView outputGrid1 = new GridView(); 
outputGrid1.ShowHeader = false; // Remove the integer headings. 
outputGrid1.DataSource = flipped_ds1; 
outputGrid1.DataBind(); 
outputGrid1.AutoGenerateEditButton = true; 
Controls.Add(outputGrid1); 

現在,按照我想要的方式添加列,並正確填充數據。但是,我沒有編輯按鈕,我認爲我應該通過將GridView.AutoGenerateEditButton屬性設置爲true。我確信我錯過了一件簡單的事情;有人可以幫忙嗎?非常感謝。

回答

1

您是否曾嘗試在調用DataBind()之前設置AutoGenerateEditButton?有沒有辦法阻止你的數據集中的更新(內省可能會檢測到它,並避免提供一個無用的按鈕)?

+0

就是這樣。我只需要在DataBind之前聲明它。非常感謝! –

相關問題