我有一个GridView
从我的SQL
. 网格的页面大小为 7。我正在利用该RowDataBound
事件将“<”和“>”字符替换为“`”,这可以按预期工作。
但是,问题在于它Paging
在网格上禁用。RowDataBound
当网格有超过 7 个项目时,应该启用分页,以便我可以转到第 2 页,但是一旦我使用该事件,分页就不起作用。
我的代码
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserID"] != null)
{
GrdOpsBook.DataSource = OperationalEmployees.getEmpbookedBySpecificDate(DateTime.Today);
GrdOpsBook.DataBind();
if (GrdOpsBook.Rows.Count == 0)
lblNoOpsBooking.Visible = true;
lblWelcome.Text = "Welcome " + Session["UserLoggedInName"] + " to the Energy Insight Booking Application";
}
else
Response.Redirect("LogIn.aspx");
}
protected void GrdOpsBook_RowDataBound1(object sender, GridViewRowEventArgs e)
{
foreach (TableCell cell in e.Row.Cells)
{
cell.Text = cell.Text.Replace(">", "`");
cell.Text = cell.Text.Replace("<", "`");
}
}
我的网格视图
<asp:GridView ID="GrdOpsBook" runat="server" BackColor="White" BorderColor="#DEDFDE" BorderStyle="None" BorderWidth="1px"
CellPadding="4" AllowPaging="True" EnableSortingAndPagingCallbacks="True"
PageSize="7"
ForeColor="Black" GridLines="Vertical" Width="100%" AutoGenerateColumns="False" >
<AlternatingRowStyle BackColor="LightGray" />
<FooterStyle BackColor="#CCCC99" />
<HeaderStyle BackColor="#6B696B" Font-Bold="True" ForeColor="White" />
<PagerStyle ForeColor="Black" HorizontalAlign="Right" BackColor="#F7F7DE" />
<RowStyle BackColor="#F7F7DE" />
<SelectedRowStyle BackColor="#CE5D5A" Font-Bold="True" ForeColor="White" />
<SortedAscendingCellStyle BackColor="#FBFBF2" />
<SortedAscendingHeaderStyle BackColor="#848384" />
<SortedDescendingCellStyle BackColor="#EAEAD3" />
<SortedDescendingHeaderStyle BackColor="#575357" />
<Columns>
<asp:BoundField DataField="Operator" HeaderText="Operator" ItemStyle-Width="10%" ItemStyle-Wrap="false" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="Destination" HeaderText="Destination" ItemStyle-Width="58%" HtmlEncode="false" ItemStyle-Wrap="true"/>
<asp:BoundField DataField="Start Time" HeaderText="Start Time" ItemStyle-Width="6%" HtmlEncode="false" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:hh\:mm}" />
<asp:BoundField DataField="End Time" HeaderText="End Time" ItemStyle-Width="6%" HtmlEncode="false" ItemStyle-HorizontalAlign="Center" DataFormatString="{0:hh\:mm}" />
<asp:BoundField DataField="Booked By" HeaderText="Booked By" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center"/>
<asp:BoundField DataField="Number of Days Booked" HeaderText="Number of Days Booked" ItemStyle-Width="10%" ItemStyle-HorizontalAlign="Center" />
</Columns>
</asp:GridView>