How to GridView Header Hide Using Asp.Net C#

GRIDVIEW   HEADER  HIDE


Gridview  Header  Hide  in Run Time   Using Gridview Property ShowHeader.

                   DEMO







Html Coding :



<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title> 

</head>
<body>
    <form id="form1" runat="server">
    <div>      
        <asp:GridView ID="GridView1" runat="server"  ShowHeader ="false" >
        </asp:GridView>     
               
    </div>
    </form>
</body>
</html>



        C# Coding 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class _Default : System.Web.UI.Page
{
    SqlConnection con;
    SqlCommand cmd;
    SqlDataAdapter adp;
    SqlDataReader rd;
    DataSet ds;
    string query;

    public void dbcon()
    {
        string connn = (System.Configuration.ConfigurationManager.ConnectionStrings["dbcon"].ToString());
        con = new SqlConnection(connn);
        con.Open();

    }

    protected void Page_Load(object sender, EventArgs e)
    {

        dbcon();
        query = "select * from reg";
        cmd = new SqlCommand(query, con);
        adp = new SqlDataAdapter(cmd);
        ds = new DataSet();
        adp.Fill(ds);
        rd = cmd.ExecuteReader();
        if (ds.Tables[0].Rows.Count > 0)
        {
            GridView1.DataSource = ds;
            GridView1.DataBind();
        }
        else
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            GridView1.DataSource = ds;
            GridView1.DataBind();
            int columncount = GridView1.Rows[0].Cells.Count;
            GridView1.Rows[0].Cells.Clear();
            GridView1.Rows[0].Cells.Add(new TableCell());
            GridView1.Rows[0].Cells[0].ColumnSpan = columncount;
            GridView1.Rows[0].Cells[0].Text = "No Records Found";
        }
    }

}



First  - Add New Web Form -  Select  GridView  From Data ToolBox 









Next - GridView Property (F4 ) -  Go to  ShowHeader = False  
















Next - Go to  the  Coding Page - Add the NameSpaces  & Database Connection 








     Next  -  Coding  Select Query  for Table(reg)   in Page Load 







OUTPUT

Next  -  F5 Run The Web Form  -  reg Table Values Display 
 GridView Header hide

ShowHeader=false









Suppose  Gridview Property ShowHeader = True   Show the Header







                                                         

0 comments:

Post a Comment