110,534
社区成员
发帖
与我相关
我的任务
分享
<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)
{
int newPageIndex = 0;
// 当点击first, last, previous and next按钮时处理
newPageIndex = e.NewPageIndex;
// 对PageIndex溢出处理
newPageIndex = newPageIndex < 0 ? 0 : newPageIndex;
newPageIndex = newPageIndex >= this.gvProgram.PageCount ? this.gvProgram.PageCount - 1 : newPageIndex;
// 更新PageIndex
this.gvProgram.PageIndex = newPageIndex;
}
BLLFile bllFile = new BLLFile();
//取得数据集
DALItoy.TblFileDataTable dataTable = bllFile.GetListByFileTypeAndHost(this.hidHost.Text, this.hidFileType.Text);
//取得记录总数
recordCount = dataTable.Rows.Count;
//补空行
for (int i = recordCount%gvProgram.PageSize; i < gvProgram.PageSize; i++)
{
DALItoy.TblFileRow row = dataTable.NewTblFileRow();
row.FileName = " ";
row.FilePath = " ";
row.FileSize = 0;
row.FileType = " ";
dataTable.AddTblFileRow(row);
}
//绑定数据
this.gvProgram.DataSource = dataTable;
this.gvProgram.DataBind();
<asp:ImageButton ID="downloadPM" runat="server" Visible='<%# Eval("FileName") != " "%>' OnClick="ImageButton_Click" CommandArgument='<%# Eval("FilePath") %>'/>