Question : Access control inside nested gridview

Hello experts,

I have a gridview nested within a gridview.


   


Within Gridview 2 I have a linkbutton which has an event and on that event I would like to get access to it's parents gridview key value.

So for instance this usually works if the gridview is not nested like attached (below).

So I think what is needed is to get the row's parent (which is gridview2) and go from there. So my question is how can I get access to gridview2 using the code below?

Thanks

Code Snippet:
1:
2:
3:
4:
5:
6:
7:
protected void LinkButton1_Click(object sender, EventArgs e)
    {
        LinkButton lb1 = (LinkButton)sender;
        GridViewRow row = (GridViewRow)lb1.NamingContainer;
        
        long intOrderItemId = Convert.ToInt64(GridView2.DataKeys[row.RowIndex].Value);
    }

Answer : Access control inside nested gridview

I found this in my drawer.
I don't know where I got it, but there's the attribution at the top:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
'### (c) Gernot Hummer, 2004 
Const ENCRYPTION_KEY = "1234567890ABCDEF1234567890ABCDEF1234567890ABCDEF12"
Dim pwstrings List As String

Function Encrypt( PasswordClear As String )
	'Function returns encrypted string.
	Dim encryptedarray List As String
	Dim pwarray List As String
	Dim hexvalue As String
	Dim decvalue As Integer
	Dim i As Integer
	i = 0

	Call GeneratePasswordArray ( PasswordClear )

	Forall character In pwstrings
		hexvalue = "&H" & GetTransposeSegment( i )
		decvalue = Cint( hexvalue )
		encryptedarray( i ) = Chr( SwapCodeTable( Asc( character ) + decvalue ) )
		i = i + 1
	End Forall

	Encrypt = ArrayBackToString( encryptedarray )
	Erase pwstrings
End Function

Function Decrypt( PasswordEncrypted As String )
	'Function returns decrypted string.
	Dim encryptedarray List As String
	Dim hexvalue As String
	Dim decvalue As Integer
	Dim i As Integer
	i = 0

	Call GeneratePasswordArray ( PasswordEncrypted )

	Forall character In pwstrings
		hexvalue = "&H" & GetTransposeSegment( i )
		decvalue = Cint( hexvalue )
		encryptedarray( i ) = Chr( SwapCodeTable( Asc( character ) - decvalue ) )
		i = i + 1
	End Forall

	Decrypt = ArrayBackToString( encryptedarray )
	Erase pwstrings
End Function

Function GeneratePasswordArray( Password As String )
	'Function returns an array with all characters of the password string.
	Dim i As Integer
	i = 0

	For i = 1 To Len( Password )
		pwstrings( i ) = Mid( Password, i , 1 )
	Next i

	GeneratePasswordArray = pwstrings
End Function

Function ArrayBackToString( PasswordArray List As String )
	'Function returns a string consisting of all characters in the array.
	Dim pwstring As String
	Forall character In PasswordArray
		pwstring = pwstring + character
	End Forall
	ArrayBackToString = pwstring
End Function

Function GetTransposeSegment( i As Integer )
	'Function returns the element of the PASSWORD_KEY on position i.
	'If i is greater than the length of the key, the last element of the key will be returned.
	If i < Len( ENCRYPTION_KEY ) - 1 Then 
		GetTransposeSegment = Mid( Cstr( ENCRYPTION_KEY ), i + 1, 1 )
	Else
		GetTransposeSegment = Mid( Cstr( ENCRYPTION_KEY ), 50, 1 )
	End If
End Function

Function SwapCodeTable( i As Integer )
	'Function ensures, that only valid ascii-codes are used.
	If i > 122 Then
		SwapCodeTable = i - 75
	Elseif i < 48 Then
		SwapCodeTable = i + 75
	Else
		SwapCodeTable = i
	End If 
End Function
Random Solutions  
 
programming4us programming4us