2012-08-11 3 views

답변

3

가장 쉬운 방법은 DataKeyNames의 String 배열을 ArrayList로 변환하고 새 DataKeyName을 추가 한 다음이 ArrayList를 String() 배열로 변환 한 다음이를 사용하여 Gridview의 DataKeyNames 속성을 설정하는 것입니다.

Dim arr As New ArrayList() 
Dim keys As String() = GridView1.DataKeyNames 

//Convert to an ArrayList and add the new key. 
arr.AddRange(keys) 
arr.Add("New Key") 

//Convert back to a string array and set the property. 
Dim newkeys As String() = CType(arr.ToArray(Type.GetType("System.String")), String()) 
GridView1.DataKeyNames = newkeys 
3

//get length of existing keys 
int keyLength = MyGrid.DataKeyNames.Length; 

//create newkeys array with an extra space to take the new key 
string[] newkeys = new string[keyLength+1]; 

//copy the old keys to the newkeys array 
for (int i = 0; i < keyLength; i++) 
    newkeys[i] = MyGrid.DataKeyNames[i]; 

//add the new key in the last location 
newkeys[keyLength] = "MyNewKey"; 

//update your datakeys 
MyGrid.DataKeyNames = newkeys; 
을 시도 예를 들면 다음과 같습니다