The GridView table header is displayed when no records are recorded, and an additional line is displayed when "no Record" "Bind SqlDataSource Control"

Source: Internet
Author: User

The original Published time: 2008-08-04--from my Baidu article [imported by moving tools]

Using System;
Using System.Data;
Using System.Configuration;
Using System.Collections;
Using System.Web;
Using System.Web.Security;
Using System.Web.UI;
Using System.Web.UI.WebControls;
Using System.Web.UI.WebControls.WebParts;
Using System.Web.UI.HtmlControls;

Public partial class Default2:System.Web.UI.Page
{
    protected void Page_Load (object sender , EventArgs e)
    {
        if (! IsPostBack)
        {
             if (GridView1.Rows.Count = = 0)

                Creatheader ();
        
       }
    }
    protected void detailsview1_iteminserted (object sender, DetailsViewInsertedEventArgs e)
    {
         Gridview1.databind ();
        gridview1.pageindex = gridview1.pagecount-1;
   }
    protected void Gridview1_databound (object sender, EventArgs e)
    {

}
protected void gridview1_rowcreated (object sender, GridViewRowEventArgs e)
{

}
private void Creatheader ()
{
DataTable dt = new DataTable ();
Dt. Columns.Add ("id");
Dt. Columns.Add ("name");
Dt. Columns.Add ("class");
Dt. Rows.Add (dt. NewRow ());

Gridview1.datasourceid = "";//If the SqlDataSource control is previously bound, this sentence must be written on

        gridview1.datasource = DT;
        Gridview1.databind ();
        int columnCount = dt. Columns.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 record";
        Gridview1.rows[0]. Cells[0]. Style.add ("Text-align", "center");
   }

protected void gridview1_rowdeleted (object sender, Gridviewdeletedeventargs e)
{
if (GridView1.Rows.Count ==1)
Creatheader ();
}
}

The GridView table header is displayed when no records are recorded, and an additional line is displayed when "no Record" "Bind SqlDataSource Control"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.