Hide Gridview column at Runtime in ASP .net.

Hide Gridview column at Runtime in ASP .net.

Hello Everyone,

In this post going to share to code-sample for the hide gridview column at run-time using asp.net with c#

Table of Contents

1. In the 1st steps, code-sample for collection class for returns dataSet.
2. In the 2nd steps, code-sample for bind the grid view and hide row from grid view at the run time.

In the step 1st

/// <summary>
/// Collection Class is used to return dataset.
/// </summary>
public class CollectionClass
{
    /// <returns>DataSet</returns>
    public DataSet GetVideofile()
    {
        DataSet dsVideo = null;
        string spNamehere = "sp_getCWVideos";
        Hashtable paramTable = new Hashtable();
        dsVideo = System.Web.DataAccess.ExecuteSP(spNamehere, paramTablehere);
        return dsVideo;
    }
}

In the step 2nd

/// <summary>
/// Page load event is used to bind the data sourses.
/// </summary>
protected void Page_Load(object sender, EventArgs e)
{
    try
    {
        CollectionClass objcollcls = new CollectionClass();
        GridViewID.DataSource = objcollcls.GetVideofile();
        GridViewID.DataBind();

        GridViewID.HeaderRow.Cells[5].Visible = false;
        foreach (GridViewRow objgvr in GridViewID.Rows)
        {
            objgvr.Cells[5].Visible = false;
        }
    }
    catch (Exception ex)
    {
        lblMessagetext.Text = ex.Message;
    }
}


ANIL SINGH

Anil Singh is an author, tech blogger, and software programmer. Book writing, tech blogging is something do extra and Anil love doing it. For more detail, kindly refer to this link..

My Tech Blog - https://www.code-sample.com/
My Books - Book 1 and Book 2

www.code-sample.com/. Powered by Blogger.
^