Completely Free .NET word API

Resources » .NET programming » ASP.NET/Web Applications

How to add a blank row after every n rows of GridView.

Updated: Category: ASP.NET/Web Applications
Author: Member Level: GoldPoints: 10


In this article i will explain how to add a blank row after every n rows of a gridview:


To achieve this functionality we will have a gridview in design view .

In the code behind we have this code.Here we have used 5th row to display blank row.

& lt asp:GridView ID="gdview" runat="server" AutoGenerateColumns="False"& gt
& lt Columns& gt
& lt asp:BoundField HeaderText="Category Name" DataField="catname" & gt
& lt ItemStyle Height="20px" Width="150px" /& gt
& lt /asp:BoundField& gt

& lt /Columns& gt

& lt /asp:GridView& gt

protected void Page_Load(object sender, EventArgs e)

if (!Page.IsPostBack)



public void bindgrid()
SqlConnection conn = new SqlConnection("Data Source='localhost';Initial Catalog='Northwind';Integrated Security=SSPI;Persist Security Info=False ");

SqlDataAdapter da = new SqlDataAdapter("", conn);
da.SelectCommand = new SqlCommand("select CategoryName,CategoryID from Categories", conn);
DataSet ds = new DataSet();
da.Fill(ds, "data");
DataTable dtable = new DataTable();
int k = 5;//here istead of 5 you can put 'n'th row.
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
DataRow r = dtable.NewRow();
if ((i+1) == k)
r[0] = "";
k = k + 5;
r[0] = ds.Tables[0].Rows[i].ItemArray[0].ToString();


gdview.DataSource = dtable;



Here we have assigned categories table in the northwind database to
the datasource. We have used dtable to assign an empty row after n records ie
5 in this case.we have looped the rows untill we reach our specific row and
assigned a blank row in that area.Finally we have binded this datatable to the gridview

Did you like this resource? Share it with your friends and show your love!

Responses to "How to add a blank row after every n rows of GridView."
Author: Manindra Kumar Upadhyay  29 Apr 2010   Member Level: Gold   Points : 1
try this link:

Author: Kunal  30 Apr 2010   Member Level: Bronze   Points : 1
what about the performance of this code?
if i have 100 rows to bound then..
is it go slow or not?


Post Comment:

  • Do not include your name, "with regards" etc in the comment. Write detailed comment, relevant to the topic.
  • No HTML formatting and links to other web sites are allowed.
  • This is a strictly moderated site. Absolutely no spam allowed.
  • Name:   Sign In to fill automatically.
    Email: (Will not be published, but required to validate comment)

    Type the numbers and letters shown on the left.

    Submit Article     Return to Article Index
    Subscribe to Subscribers
    Active Members
    TodayLast 7 Daysmore...

    Awards & Gifts
    Talk to Webmaster Tony John
    Copyright © SpiderWorks Technologies Pvt Ltd., Kochi, India