Question : ASP.NET Gridview with linkbutton

I have a gridview with linkbutton in it. But I'm hving trouble using the datakey value in my codebehind. I get an error "System.FormatException: Input string was not in a correct format."

Any help on accessing the datakeynames value?
Code Snippet:
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:

                            
                            
                            
                                
                                    
                                        <%# Eval("xLabel") %>
                                    
                                
                                        
                        
 
 
    Protected Sub GridTree_RowCommand(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCommandEventArgs) Handles GridTree.RowCommand
        Dim yNode As Integer
        yNode = Me.GridTree.DataKeys(Integer.Parse(e.CommandArgument.ToString())).Value
        Dim yChunk As Integer
        yChunk = xGetChunkId(yNode)
        Select Case e.CommandName
            Case "NodeSelected"
                If yChunk Then
                    ViewState("vsTreeParent") = Me.GridTree.DataKeys(Integer.Parse(e.CommandArgument.ToString())).Value
                    Call xShowTreeNodes(ViewState("vsTreeParent"))
                Else
                    xShowChunk(yChunk)
                End If
        End Select
    End Sub

Answer : ASP.NET Gridview with linkbutton

Because you'll have to write the linkbutton tag like this

runat="server" style="text-decoration:none; color:#000000; " CommandArgument='<% #Eval("xId") %'> ><%# Eval("xLabel") %>

And in codebehind like this

ViewState("vsTreeParent") = e.CommandArgument.ToString()
Random Solutions  
 
programming4us programming4us