我的表单上有一个 GridView。我已将其 DataSource 设置为 DataTable。我像这样检索 DataTable:
SELECT AMOUNT, ISSUEDATE,REASON FROM PAYMENTS WHERE
PENSIONERID=113 ORDER BY ISSUEDATE DESC
当我在服务器端运行这个查询时,我得到了三个记录。但是在我的网页上,gridview 只显示了其中的两个。后面的代码没有设置任何条件会导致 gridview 不显示任何类型的记录。一段时间后,当我重新启动服务器时,我可以在 gridview 中看到第三行。这是与我的 IIS 相关的问题吗?无论如何可能是什么原因?谢谢。
这是 GridView 和数据加载代码:
<asp:GridView ID="gvOdanBirm" runat="server" AllowPaging="True"
AutoGenerateColumns="False" CellPadding="4" ForeColor="#333333"
GridLines="None" OnPageIndexChanging="gvPayments_PageIndexChanging"
PageSize="3">
<FooterStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<Columns>
<asp:BoundField DataField="ISSUEDATE" HeaderText="Issue date">
<ItemStyle BorderColor="#01055E" BorderStyle="Solid" BorderWidth="1px"
HorizontalAlign="Right" Width="70px" />
<HeaderStyle BorderColor="#01055E" BorderStyle="Solid" BorderWidth="1px" />
</asp:BoundField>
<asp:BoundField DataField="AMOUNT" HeaderText="Amount">
<ItemStyle BorderColor="#01055E" BorderStyle="Solid" BorderWidth="1px"
HorizontalAlign="Right" Width="30px" />
<HeaderStyle BorderColor="#01055E" BorderStyle="Solid" BorderWidth="1px" />
</asp:BoundField>
<asp:BoundField DataField="REASON" HeaderText="REASON"
>
<ItemStyle BorderColor="#01055E" BorderStyle="Solid" BorderWidth="1px"
HorizontalAlign="Left" Width="50px" />
<HeaderStyle BorderColor="#01055E" BorderStyle="Solid" BorderWidth="1px" />
</asp:BoundField>
</Columns>
<RowStyle BackColor="#F7F6F3" ForeColor="#333333" />
<EditRowStyle BackColor="#999999" />
<SelectedRowStyle BackColor="#E2DED6" Font-Bold="True" ForeColor="#333333" />
<PagerStyle BackColor="#284775" ForeColor="White" HorizontalAlign="Center" />
<HeaderStyle BackColor="#5D7B9D" Font-Bold="True" ForeColor="White" />
<AlternatingRowStyle BackColor="White" ForeColor="#284775" />
</asp:GridView>
代码隐藏:
gvPayments.DataSource= GetPayments(pensionerID);
gvPayments.DataBind();
最佳答案
您可以尝试以下操作吗?
查看该行未出现时生成的页面的源代码...该行是否根本没有进入页面?或者它只是出于某种原因没有显示?
当第三行没有出现时,你可以通过移动到下一页来获得它吗?暂时从aspx代码中取出分页命令,看是否能解决。
检查服务器是否包含最新的数据库、操作系统和 IIS 的所有服务包等。
您正在运行哪个版本的 IIS?什么服务器操作系统?
您能否发布
gvPayments_PageIndexChanging
背后的代码,以及构建 gridview 背后的任何代码?您使用什么浏览器查看结果?出现错误时,您可以尝试使用其他浏览器或其他机器吗?你得到相同的结果吗?
忘记了一个大问题...您可以在
gvPayments.DataSource= GetPayments(pensionerID);
之后中断吗?您是否从数据库中检索了所有三行?也许您的问题不在 aspx 代码中,而是在您要返回绑定(bind)的数据中。
发布这些内容时会考虑更多。
关于c# - GridView 不显示所有行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10396611/