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