You must Sign In to post a response.
  • Category: ASP.NET

    How To hide Coloums If it is Empty or Null

    Hi
    I have create a application in this application a give a Grid view.
    at the time of binding the grid view some rows are empty, then
    How to Hide this Row ?
  • #725788
    Hi,
    try the following code:
    protected void GridView1_RowDataBound(object sender, System.Web.UI.WebControls.GridViewRowEventArgs e)
    {
    if (e.Row.RowType == DataControlRowType.DataRow)
    {
    string strRow = e.Row.Cells[0].Text;
    if (string.IsNullOrEmpty(strRow) | strRow.Length == 0)
    {
    e.Row.Visible = false;
    }
    }
    }

    Thanks

    Reena

  • #725799
    Hi,

    You can do this on GridView row databound event itself. Use below sample code


    protected void GV_RowDataBound(object sender,GridViewRowEventArgs e)
    {
    if(e.Row.RowType==DataControlRowType.DataRow)
    {
    string val=((Label) e.Row.FindControl("lblVal")).Text;
    if(val=="")
    {
    ((Label) e.Row.FindControl("lblVal")).Visible= false;
    }
    }
    }


    Try something like this.

    Here what i did is if the value is empty then i just disable that control.

    Hope this will resolve your problem....

    --------------------------------------------------------------------------------
    Give respect to your work, Instead of trying to impress your boss.

    N@veen
    Blog : http://naveens-dotnet.blogspot.in/


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.