GridView Header With NO DATA FOUND meassage

GridView Header With NO DATA FOUND meassage

In this article I am showing gridview NO DATA MESSAGE   with header.in normal case whenever gridview found no row for display it will just show its NO DATA FOUND message by defining  its  EmptyDataText="No Data Found"  bLock.So Now You can display meassage with its Header.


.aspx Part.

Desgin Page with Gridview.


<form id="form1" runat="server">
        <div>

            <asp:GridView ID="gr" runat="server">
                <HeaderStyle BackColor="Yellow" ForeColor="Red" Width="20px" />

            </asp:GridView>

        </div>
    </form>

.CS Part.

In CS part i am using a convance  table with no Data.And i think everything is straight forward and easy.



SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["KANDY"].ToString());
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindGridData();
        }
    }
    protected void BindGridData()
    {

        con.Open();
        string qu = "select * from convance";
        SqlDataAdapter da = new SqlDataAdapter(qu, con);
        DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count == 0)
        {
            ds.Tables[0].Rows.Add(ds.Tables[0].NewRow());
            gr.DataSource = ds;
            gr.DataBind();
            int columncount = gr.Rows[0].Cells.Count;
            gr.Rows[0].Cells.Clear();
            gr.Rows[0].Cells.Add(new TableCell());
            gr.Rows[0].Cells[0].ColumnSpan = columncount;
            gr.Rows[0].Cells[0].Text = "No Data Found";
        }
        else
        {
            gr.DataSource = ds;
            gr.DataBind();


        }

        con.Close();
    }


}

OutPut will Look Like :-



Comments

Popular posts from this blog

Create and save QR code in asp.net with C#

Change text of RadGrid Header Dynamically

Telerik Radwindow Open on Button Click