ASP.NET GridView手动改变行数
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections;
using System.Drawing;
public partial class PackingInfo : System.Web.UI.Page
{
ReportsManager rm = new ReportsManager();
// 设置每页显示的行数
int TotalRowCount = 12;
// 自动填充的行数
int numCount = 0;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
this.txtCartonQty.Focus();
ViewState["SortOrder"] = "CTN NO";
ViewState["OrderDire"] = "ASC";
}
}
DataTable dt = new DataTable();
string CartonSN = string.Empty;
string _CartonSN = string.Empty;
// 计算数据,这里可以适当修改从数据库中获取
ICollection CreateDataSource(int RowsCount)
{
System.Data.DataTable dt = new System.Data.DataTable();
System.Data.DataRow dr;
dt.Columns.Add(new System.Data.DataColumn("P/N", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("CTN NO", typeof(System.String)));
dt.Columns.Add(new System.Data.DataColumn("CustomerSN", typeof(System.Decimal)));
for (int i = 0; i < RowsCount; i++)
{
dr = dt.NewRow();
dt.Rows.Add(dr);
}
System.Data.DataView dv = new System.Data.DataView(dt);
return dv;
}
protected void gv_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Cells[3].Attributes.Add("style", "vnd.ms-excel.numberformat:@");
}
int m;
for (m = 0; m < gv.Rows.Count; m++)
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor,this.style.backgroundColor='#00A9FF'");
e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c");
}
}
try
{
if (e.Row.RowType == DataControlRowType.DataRow)
{
// 计算自动填充的行数
numCount++;
}
if (e.Row.RowType == DataControlRowType.Footer)
{
//在此添加缺少的行
int toLeft = TotalRowCount - numCount;
int numCols = gv.Rows[0].Cells.Count;
for (int i = 0; i < toLeft; i++)
{
GridViewRow row = new GridViewRow(-1, -1, DataControlRowType.EmptyDataRow, DataControlRowState.Normal);
for (int j = 0; j < numCols; j++)
{
TableCell cell = new TableCell();
cell.Text = " ";
row.Cells.Add(cell);
}
gv.Controls[0].Controls.AddAt(numCount + 1 + i, row);
}
}
}
catch (Exception ex)
{
this.lblMessage.Text = ex.Message;
this.lblMessage.ForeColor = Color.Red;
}
if (e.Row.RowIndex != -1)
{
int id = e.Row.RowIndex + 1;
e.Row.Cells[0].Text = id.ToString();
}
}
}
Allen Chen 的专栏
最近更新
随机推荐
- Joomla!多个远程安全漏洞
- 虚商发展模式浅析:“喜牛”模式新突
- Cisco IOS网络操作系统中AAA RADIUS认
- 黑客工具可将恶意软件隐藏于.Net框架
- 姚劲波沉默应对58同城赴美上市传言
- 大浪淘沙方显英雄本色 掌门1对1等头部
- 华为否认做电商:不会跨界卖肉 没有和
- 岂曰无衣 与子同袍 |银盛泰国际控股有
- 法院叫停西瓜视频:立即停止《王者荣
- Uber拟31亿美元收购迪拜打车公司Care
- 海水或火焰 微贷网的汽车金融发展之路
- 美国政府网多次被黑 士兵信息被曝光
- 新品发布|中科奥森重磅打造智能硬件核
- Twitter 遭拒绝服务安全一周三次宕机
- 两个“搜房”之间的商标战争
- 微信围剿“手游”概念股 推广渠道“最
- MS06-045:Windows资源管理器中远程执
- Intel处理器的漏洞容易受到安全安全
- 2010年全球12大著名白帽黑客憾无华裔
- 360和有道,在一起,真的有意义?