---
title: "number of columns using rowdatabound in asp.net"  
description: "number of columns using rowdatabound in asp.net"  
author: "Anonymous User"  
published: 2014-11-27  
updated: 2014-11-27  
canonical: https://www.mindstick.com/forum/12698/number-of-columns-using-rowdatabound-in-asp-dot-net  
category: "asp.net"  
tags: ["asp.net", "gridview"]  
reading_time: 1 minute  

---

# number of columns using rowdatabound in asp.net

I need to find [count](https://www.mindstick.com/forum/157774/selecting-count-with-distinct) of total number of columns in a [gridview](https://www.mindstick.com/articles/873/update-delete-edit-gridview-in-asp-dot-net) inside the [event](https://www.mindstick.com/articles/167719/marquee-hire-benefits-of-event-lighting-hire-london) [rowdatabound](https://www.mindstick.com/forum/12667/gridview-rowdatabound-for-loop-not-working) .Is there any way for it. Below is my few [code](https://yourviews.mindstick.com/view/85458/alan-turing-the-mastermind-behind-cracking-the-enigma-code-during-world-war-ii):

```
   protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)        {            LinkButton lnkView = new LinkButton();            lnkView.ID = "lnkView";            lnkView.Text = "View";            lnkView.Click += ViewDetails;             e.Row.Cells[3].Controls.Add(lnkView);        }
```

## Replies

### Reply by Pravesh Singh

You can cast sender to GridView and get the count.

```
protected void gvEmployee_RowDataBound(object sender,GridViewRowEventArgs e){          if(!(sender is GridView))        return;    GridView gridView= (GridView) sender;    var colCount =gridView.Columns.Count;   //Your code}
```


---

Original Source: https://www.mindstick.com/forum/12698/number-of-columns-using-rowdatabound-in-asp-dot-net

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
