2012-03-06 38 views
-4

可能重複:
How to check which cells from gridview were edited?任何機會檢查極其細胞被編輯?

我想知道我怎麼能檢查是否從gridview的細胞編輯與否。

+0

你不需要3個單獨的帖子一個問題 dupe -http://stackoverflow.com/questions/9588332/how-to-check-edited-cells-in-gridview-then-add-their-values -into-a-textbox http://stackoverflow.com/questions/9585463/how-to-check-which-cells-from-gridview-were-edited – 2012-03-06 19:09:42

回答

1

您可以使用RowUpdated事件來檢查是否由GridViewUpdatedEventArgs參數。有兩個名爲OldValues和NewValues的屬性,您可以檢查更新的內容(舊值是新聞值的差異)。

+0

我知道,但我不知道如何檢查哪些單元格已更新 – 2012-03-06 19:20:11

+0

在DisplayValues方法中查看此示例,可以爲每個項目添加一個「if」語句(按索引)以檢查它是否不同。 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdatedeventargs.aspx – 2012-03-06 19:55:33

+0

是的我知道,但我需要全球性的東西,如果沒有添加,如果..如果.. ..許多if條件 – 2012-03-06 19:59:35

1

檢查這部分代碼從 http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridviewupdatedeventargs.newvalues%28v=vs.80%29.aspx

void DisplayValues(OrderedDictionary newValues, OrderedDictionary oldValues) 
    { 

    Message.Text += "<br/></br>"; 

    // Iterate through the new and old values. Display the 
    // values on the page. 
    for (int i = 0; i < oldValues.Count; i++) 
    { 
     Message.Text += "Old Value=" + oldValues[i].ToString() + 
     ", New Value=" + newValues[i].ToString() + "<br/>"; 
    } 

    Message.Text += "</br>"; 

    } 

你可以用它來表示

txtbox.Text = "name changed from" + oldValues[0].ToString() + 
      " to " + newValues[0].ToString(); 

我認爲這應該幫助你。