Prompt for binding an empty table to the GridView

Source: Internet
Author: User

When the query result is blank, a prompt is not displayed, but an empty table is bound directly. The first column in the empty table is description. Code:

// If no query result is found, bind an empty table with a prompt
If (ds. Tables [0]. Rows. Count = 0)
{
// Add a new row to the empty table
Ds. Tables [0]. Rows. Add (ds. Tables [0]. NewRow ());
// Bind an empty table to the gridview
This. GV_MCText.DataSource = ds;
This. GV_MCText.DataBind ();
// Obtain the number of rows in the table
Int CellCount = this. GV_MCText.Rows [0]. Cells. Count;
// Clear all columns in the first row
This. GV_MCText.Rows [0]. Cells. Clear ();
// Add a new column in the first row
This. GV_MCText.Rows [0]. Cells. Add (new TableCell ());
// This column overwrites the entire row
This. GV_MCText.Rows [0]. Cells [0]. ColumnSpan = CellCount;
// The prompt character is displayed at the end.
This. GV_MCText.Rows [0]. Cells [0]. Text = "no data ";
}

Extension: you can write a class file for all modules to call.

# Binding region user query conditions to the GridView
Public static void BindSearchReturn (GridView gv, string itcode, int search)
{
String MySql = "select SaveSearch, Names, CreateDate from GTN_SaveSearch where itcode = '" + itcode + "' and State = '0' and SearchType =" + search;
DataTable dt = LenovoFrame. Library. Data. Search. UserPersonSearch. BindSearchParam (MySql );
If (dt. Rows. Count = 0)
{
Dt. Rows. Add (dt. NewRow ());
Gv. DataSource = dt;
Gv. DataBind ();
Int CellCount = gv. Rows [0]. Cells. Count;
Gv. Rows [0]. Cells. Clear ();
Gv. Rows [0]. Cells. Add (new TableCell ());
Gv. Rows [0]. Cells [0]. ColumnSpan = CellCount;
Gv. Rows [0]. Cells [0]. Text = "No Records Found ";

}
Else
{
Gv. DataSource = dt;
Gv. DataBind ();
}

}
# Endregion

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.