【发布时间】:2016-06-21 12:09:19
【问题描述】:
Gridview 已配置:
<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>
当我单击“查看”按钮时,gvApptList_RowCommand 会触发。它的代码是:
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
gvApptList.DataKeys(e.CommandArgument).Value 总是空无返回。我在这里想念什么?我在其他页面上有这个确切的销售代码。
【问题讨论】:
-
您不需要将 DataKeyName 作为绑定的 DataField 吗?
-
AppointmentID 是否包含在您的基础 SELECT 查询中?另外,DataSource 和绑定代码在哪里?最好的问候,
-
是的,约会 ID 是数据源的一部分,它从包含所有约会详细信息的 LeadAppointments 类加载。
标签: asp.net vb.net gridview datarow datakey