Ok So this is the real Problem
try this
private void ShowNoResultFound(DataTable source, GridView gv)
{
source.Rows.Add(source.NewRow());
gv.DataSource = source;
gv.DataBind();
int columnsCount = gv.Columns.Count;
gv.Rows[0].Cells.Clear();
gv.Rows[0].Cells.Add(new TableCell());
gv.Rows[0].Cells[0].ColumnSpan = columnsCount;
gv.Rows[0].Cells[0].HorizontalAlign = HorizontalAlign.Center;
gv.Rows[0].Cells[0].ForeColor = System.Drawing.Color.Red;
gv.Rows[0].Cells[0].Font.Bold = true;
gv.Rows[0].Cells[0].Text = "NO RESULT FOUND!";
}
private void BindGridView()
{
DataTable dt = new DataTable(string user);
SqlConnection connection = new SqlConnection(GetConnectionString());
try
{
connection.Open();
string sqlStatement = "SELECT* FROM Orders WHERE UserID = @User";
SqlCommand sqlCmd = new SqlCommand(sqlStatement, connection);
sqlCmd.Parameters.AddWithValue("@User", user);
SqlDataAdapter sqlDa = new SqlDataAdapter(sqlCmd);
sqlDa.Fill(dt);
if (dt.Rows.Count > 0)
{
GridView1.DataSource = dt;
GridView1.DataBind();
}
Else
{
ShowNoResultFound(dt,GridView1);
}
}
catch (System.Data.SqlClient.SqlException ex)
{
string msg = "Fetch Error:";
msg += ex.Message;
throw new Exception(msg);
}
finally
{
connection.Close();
}
}