Gridview is configured:
<asp:GridView ID="gvApptList" runat="server" CssClass="fullwidth" AutoGenerateColumns="False" DataKeyNames="AppointmentID">
<Columns>
<asp:BoundField DataField="Designer" HeaderText="Designer" SortExpression="Designer" />
<asp:BoundField DataField="AppointmentDTM" HeaderText="Appointment Date" SortExpression="AppointmentDTM" DataFormatString="{0:MM-dd-yyyy hh:mm tt}" />
<asp:BoundField DataField="Status" HeaderText="Status" SortExpression="Status" />
<asp:BoundField DataField="Disposition" HeaderText="Disposition" SortExpression="Disposition" />
<asp:BoundField DataField="AppointmentNotes" HeaderText="Appointment Notes" SortExpression="AppointmentNotes" />
<asp:ButtonField ButtonType="Button" CommandName="viewAppointment" Text="View" />
</Columns>
</asp:GridView>
When I click the "View" button, the gvApptList_RowCommand fires off. COde for it is:
If e.CommandName = "viewAppointment" Then
Dim tApptID As Long
gvApptList.SelectedIndex = e.CommandArgument
If IsNumeric(gvApptList.DataKeys(e.CommandArgument).Value) Then
tApptID = gvApptList.SelectedDataKey.Value
Else
Exit Sub
End If
tbAppointmentID.Text = tApptID
DisplayInfo()
End If
The gvApptList.DataKeys(e.CommandArgument).Value always comes back as nothing. What am I missing here? I have this exact sale code working on other pages.
Pertinent to your task, the correct syntax using
DataKeysin ASP.NETGridViewcontrol is shown below (re: http://www.codeproject.com/Tips/225352/Nesting-GridView-control-in-ASP-NET, written in C#):You should obtain the reference to the
Rowcorresponding to the commandButtonclicked, then extract theDataKeysvalue from thatRow. Also, make sure that underlyingDataSourcecontainsAppointmentIDfield in its SELECT query.Pertinent to your case it may look like the following (see Listing 2)
Listing 2.
or you may use
TryParse(),Convert(), etc.Hope this may help.