ASP.net将空行插入到Gridview中 [英] ASP.net Insert blank rows into Gridview

查看:103
本文介绍了ASP.net将空行插入到Gridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个绑定到sqldatasource的gridview。 Gridview只有10的页面大小,我希望每个页面有10行。因此,如果只有5个数据行存在,那么我想添加5个空行。这很容易吗?

I have a gridview that is bound to a sqldatasource. The Gridview only has a pagesize of 10 and I would like each page to have 10 rows. Therefore if only 5 data rows exist then I would like to add an additional 5 empty rows. Is this easy to do?

推荐答案

将您的数据填入数据集并计算检索的行数,然后填充剩余的具有空dataRows的数据集试试这个:
假设你有一个DataSet dt填充你想要的表或数据

Fill your data into data set and count the number of rows retrieved then fill the remaining to the dataset with empty dataRows try this: Suppose you have a DataSet dt filled with the table or data you want

int remainingRows=10 - dt.Rows.Count;
DataRow dr;
for (int i = 0; i < remainingRows; i++)
{
    dr = dt.NewRow();
    dr[0] = dr[1] = dr[2] = dr[3] = dr[4] = "";//index goes the no of cols in the table
    dt.Rows.Add(dr);
}
dt.AcceptChanges();
grdView.DataSource = dt;
grdView.DataBind();

You can see this

这篇关于ASP.net将空行插入到Gridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆