【发布时间】:2017-06-29 18:24:40
【问题描述】:
在我执行以下操作之前,GridView 显示正确,因此我将描述更改,以防有人因这样做而被咬过。
我将GridView 的datasource 从“cContact”更改为“cParticipant”。 cContact 是本地班级。但是 cParticipant 是引用项目中的一个类。然而,引用的项目在解决方案中。
这是 cParticipant:
<DataContract()>
Public Class cParticipant
<DataMember()> Public Property DeptPK As Integer
<DataMember()> Public Property DistrictCompanyName As String = ""
<DataMember()> Public Property ParticipantID As String
<DataMember()> Public Property Firstname As String = ""
<DataMember()> Public Property Lastname As String = ""
<DataMember()> Public Property BusinessEmail As String = ""
<DataMember()> Public Property BusinessPhone As String = ""
<DataMember()> Public Property PersonalCellPhone As String = ""
<DataMember()> Public Property PersonalEmail As String = ""
<DataMember()> Public Property RetainContact As Boolean = True
End Class
不幸的是,我不得不同时重命名 cParticipant 及其成员。但是我已经彻底搜索了旧名称,并确保每个实例都被重命名。我仔细检查了新名称是否出现在标记的 asp:BoundField DataField="aField" 条目中。
此外,标记中提到了每个字段,没有一个被遗漏。
在 Default.aspx 的设计视图中,出现GridView,它有 5 行显示每个单元格中的“Databound”。
在 Edge 的 F12 开发者工具中,我看到了“行”会出现的地方,但 GridView 应该在的地方,它只是 <div></div>.
将成员添加到列表后,我将参与者列表绑定到GridView:
Dim C As New cParticipant
C.DeptPK=1
....
Participants.Add(C)
grdParticipantList.DataSource = Participants
grdParticipantList.DataBind()
“参与者”是 Default.aspx.vb 中的本地公共属性:
Public Property Participants() As List(Of cParticipant)
Get
Dim temp As Object = Session("Participants")
Return If(temp Is Nothing, Nothing, _
DirectCast(temp, List(Of cParticipant)))
End Get
Set(ByVal value As List(Of cParticipant))
Session("Participants") = value
End Set
End Property
更新:我在页面上扔了另一个 gridview 并将数据也绑定到它。它显示。所以我的标记肯定有问题。
下面是坏的代码和运行良好的新代码:
<div style="padding-top:20px;padding-bottom:50px;">
<div class="row">
<div class="col-lg-12 ">
<asp:GridView ID="grdParticipantList" runat="server" EnableViewState="true" DataKeyNames="ParticipantID" AutoGenerateColumns="false"
HeaderStyle-BackColor="CornflowerBlue" HeaderStyle-ForeColor="White" CellPadding="4" Width="100%"
EmptyDataText="List of participants is currently empty." CssClass="table-hover">
<Columns>
<asp:BoundField DataField="ParticipantID" HeaderText="ID" Visible="false" SortExpression="ID" HeaderStyle-CssClass="visible-lg" ItemStyle-CssClass="visible-lg" />
<asp:BoundField DataField="DeptPK" HeaderText="DeptPK" Visible="false" HeaderStyle-Width="0" ItemStyle-Width="0" SortExpression="DeptPK" />
<asp:BoundField DataField="DistrictCompanyName" HeaderText="District/Company" SortExpression="District" HeaderStyle-CssClass="visible-lg" ItemStyle-CssClass="visible-lg" />
<asp:BoundField DataField="Firstname" HeaderText="First Name" SortExpression="FName" ItemStyle-CssClass="visible-lg" HeaderStyle-CssClass="visible-lg" />
<asp:BoundField DataField="Lastname" HeaderText="LastName" SortExpression="LName" ItemStyle-CssClass="visible-lg" HeaderStyle-CssClass="visible-lg" />
<asp:BoundField DataField="BusinessEmail" HeaderText="Business Email" SortExpression="EmailB" ItemStyle-CssClass="visible-lg" HeaderStyle-CssClass="visible-lg" />
<asp:BoundField DataField="BusinessPhone" HeaderText="Business Phone" SortExpression="PhoneB" HeaderStyle-CssClass="visible-lg" ItemStyle-CssClass="visible-lg" />
<asp:BoundField DataField="PersonalEmail" HeaderText="Personal Email" SortExpression="EmailP" ItemStyle-CssClass="visible-lg" HeaderStyle-CssClass="visible-lg" />
<asp:BoundField DataField="PersonalCellPhone" HeaderText="Personal Phone" SortExpression="PhoneP" HeaderStyle-CssClass="visible-lg" ItemStyle-CssClass="visible-lg" />
<asp:BoundField DataField="RetainContact" HeaderText="Retain Info" Visible="false" SortExpression="RC" HeaderStyle-CssClass="visible-lg" ItemStyle-CssClass="visible-lg" />
<asp:TemplateField HeaderText="Retain Info" SortExpression="RC">
<ItemTemplate><%#IIf(Boolean.Parse(Eval("RetainContact").ToString()), "Yes", "No")%></ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
</div>
<asp:GridView ID="GridView1" runat="server"></asp:GridView>
【问题讨论】:
-
只是一个提示,没有人真正建立回帖页面喜欢这个并且用户不喜欢它。您是否考虑过使用 AJAX 但使用 JSON 而不是 XML?如今,Web 应用程序是 JS,服务器调用是通过 Web 服务完成的,因此没有回发。
-
您可能还想看看 ASP MVC 范例。