Search code examples
asp.netgridviewdatakey

What is the difference between following code


var id = Convert.ToInt32(GridViewVehicleList.DataKeys[e.NewSelectedIndex].Value);
var id2 = Convert.ToInt32(GridViewVehicleList.DataKeys[e.NewSelectedIndex].Values);

if i use second code as

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

, could i assign second DataKey to variable id2

Thanks for all interests


Solution

  • DataKey Properties

    Value

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

    Values

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

    So you can assign

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