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


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


Author: Manindra Kumar Upadhyay29 Apr 2010 Member Level: Gold   Points : 1

try this link:

Author: Kunal30 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?

  • 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: