日期:2014-05-18 浏览次数:20954 次
<asp:GridView ID="gvProgram" runat="server" AllowPaging="True" AutoGenerateColumns="False" DataKeyNames="ID" DataSourceID="FileDataSource" OnDataBound="gvProgram_DataBind" OnPageIndexChanging="gvProgram_PageIndexChanging" OnRowCommand="gvProgram_RowCommand" Height="498px" Width="531px" PageSize="18" OnRowDataBound="gvProgram_RowDataBound" > <PagerTemplate> <table width="100%"> <tr> <td> <asp:ImageButton ID="imageFirst" CommandName="Page" CommandArgument="First" runat="server" /> <asp:ImageButton ID="imagePrevious" CommandName="Page" CommandArgument="Prev" runat="server"/> <asp:ImageButton ID="imageNext" CommandName="Page" CommandArgument="Next" runat="server" /> <asp:ImageButton ID="imageLast" CommandName="Page" CommandArgument="Last" runat="server"/> </td> </tr> </table> </PagerTemplate> <Columns> <asp:BoundField DataField="FileName" HeaderText="标题" > </asp:BoundField> <asp:BoundField DataField="FileSize" HeaderText="文件大小"> </asp:BoundField> </Columns> </asp:GridView> <asp:ObjectDataSource ID="FileDataSource" runat="server" SelectMethod="GetListByFileTypeAndHost" TypeName="BLLFile"> <SelectParameters> <asp:Parameter DefaultValue="02" Name="fileType" Type="String" /> <asp:Parameter DefaultValue="00" Name="host" Type="String" /> </SelectParameters> </asp:ObjectDataSource>
protected void gvProgram_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // 计算自动填充的行数 numCount++; } if (e.Row.RowType == DataControlRowType.Footer) { // 计算完毕,在此添加缺少的行 int toLeft = this.gvProgram.PageSize - numCount; int numCols = this.gvProgram.Rows[0].Cells.Count; DataControlRowState rowState = (this.gvProgram.Rows[numCount - 1].RowState); for (int i = 0; i < toLeft; i++) { // 正确显示交叉行样式 rowState = (i % 2 != 0) ? DataControlRowState.Alternate : DataControlRowState.Normal; GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, rowState); for (int j = 0; j < numCols; j++) { TableCell cell = new TableCell(); cell.Text = " "; row.Cells.Add(cell); } this.gvProgram.Controls[0].Controls.AddAt(numCount + 1 + i, row); } } } protected void gvProgram_PageIndexChanging(object sender, GridViewPageEventArgs e)