number of columns using rowdatabound in

I need to find count of total number of columns in a gridview inside the event rowdatabound .Is there any way for it. Below is my few code: 

   protected void gvEmployee_RowDataBound(object sender, GridViewRowEventArgs e)
            LinkButton lnkView = new LinkButton();
            lnkView.ID = "lnkView";
            lnkView.Text = "View";
            lnkView.Click += ViewDetails;

Last updated:11/27/2014 1:47:23 AM

1 Answers

Pravesh Singh
Pravesh Singh

You can cast sender to GridView and get the count.

protected void gvEmployee_RowDataBound(object sender,GridViewRowEventArgs e)
    if(!(sender is GridView))
    GridView gridView= (GridView) sender;
    var colCount =gridView.Columns.Count;
   //Your code