NUMBER OF COLUMNS USING ROWDATABOUND IN ASP.NET

Ankit Singh

Total Post:341

Points:2389
Posted by  Ankit Singh
 976  View(s)
Ratings:
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);

        }

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: number of columns using rowdatabound in asp.net

    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

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!