2014-02-20 100 views
1
var id = Convert.ToInt32(GridViewVehicleList.DataKeys[e.NewSelectedIndex].Value); 
var id2 = Convert.ToInt32(GridViewVehicleList.DataKeys[e.NewSelectedIndex].Values); 

之間的區別,如果我使用第二個代碼是什麼下面的代碼

id2 = Convert.ToInt32(GridViewVehicleList.DataKeys[e.NewSelectedIndex].Values[1]); 

,可能我給你第二DataKey變量ID2

感謝所有利益

+4

閱讀[文件](http://msdn.microsoft.com/en-us/library/system.web .ui.webcontrols.datakey_properties(v = vs.110).aspx) – Satpal

+0

是的,你可以。你是正確的。 –

回答

1

DataKey Properties

Value

Gets the value of the key field at index 0 in the DataKey object. 

Gets an IOrderedDictionary object that contains every key field in the DataKey 
object. 

所以,你可以指定

id2 = Convert.ToInt32(GridViewVehicleList.DataKeys[e.NewSelectedIndex].Values[1]);