number of columns using rowdatabound in asp.net

Total Post:341

Points:2389
 1220  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. 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
    }

      Modified On Apr-07-2018 01:10:09 AM

Answer

NEWSLETTER

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