Home > DeveloperSection > Forums > number of columns using rowdatabound in asp.net
Ankit Singh

Total Post:341

Points:2389
Posted on    November-27-2014 12:22 AM

 ASP.Net ASP.Net  Gridview 
Ratings:


 1 Reply(s)
 630  View(s)
Rate this:

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;

            e.Row.Cells[3].Controls.Add(lnkView);

        }



Pravesh Singh

Total Post:411

Points:2881
Posted on    November-27-2014 1:47 AM

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

}


Don't want to miss updates? Please click the below button!

Follow MindStick