Argiz
asked on
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?
Any help on accessing the datakeynames value?
<asp:GridView ID="GridTree" runat="server" DataSourceId="sdsTree" AutoGenerateColumns="False" BorderWidth="0" ShowHeader="false" DataKeyNames="xId">
<RowStyle BackColor="White" Height="14" VerticalAlign="Middle" Font-Size="X-Small" />
<AlternatingRowStyle BackColor="#B5B4B2" Height="14" VerticalAlign="Middle" Font-Size="X-Small" />
<Columns>
<asp:TemplateField ItemStyle-Width="173">
<ItemTemplate>
<asp:LinkButton ID="linkTree" CommandName="NodeSelected" runat="server" style="text-decoration:none; color:#000000; "><%# Eval("xLabel") %></asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
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
e.CommandArgument will be null and you are converting null into integer that's why the error.
ASKER
And why will e.CommandArgument be NULL?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Fixed. Thanks.
Put an if condition in the rowCommand event
if(e.CommandName=="NodeSel
then only execute your code
Anurag