emptydatatext is not displaying when binding datatable to gridview
<p>I am creating a datatable and adding rows dynamically and am binding datatable to gridview when there are no records am displaying as no records found using emptydatatext but this is not working.Here is my code</p>

<pre><code>  protected void show_fence_report(object sender, EventArgs e)
  {

    int drp_fence_id              = common.make_int(common.get_request("drp_fence"));
    string fence_start_date_time1 = common.get_request("fence_start_date_time");
    string fence_end_date_time1   = common.get_request("fence_end_date_time");

    //Delete data from datatable and gridview
    dt_fence.Clear();

    if (gridview_fence.DataSource != null)
    {
        ((DataView)gridview_fence.DataSource).Table.Clear();
    }
    gridview_fence.DataBind();
    gridview_fence.EmptyDataText = "Records Not Found";

    hid_fence_id.Value = drp_fence_id.ToString();
    hid_fence_start_datetime.Value = fence_start_date_time1;
    hid_fence_end_datetime.Value = fence_end_date_time1;

    display_fence_report();

    gridview_fence.EmptyDataText = "Records Not Found";

}

public void display_fence_report()
{

    string fence_id1 = "", fence_name1, fence_type1 = "", fence_status;
    float default_size = 100000, landmark_latitude1 = 0, landmark_longitude1 = 0, fence_latitude1 = 0, fence_longitude1 = 0, fence_size1 = 0, longitude_x = 0, latitude_y = 0;
    int points_polygon = 0;      


    ArrayList vertices_x = new ArrayList();
    ArrayList vertices_y = new ArrayList();

    query = "select latitude,longitude,added_date_time,speed,location,(select object_value from tracking_master_objects where object_id = a.object_id) as object from tracking_data_domain a where object_id in(select object_id from tracking_assign_fence a where fence_id = '" + hid_fence_id.Value + "' and is_active = '1') and (added_date_time between convert(datetime, '" + hid_fence_start_datetime.Value + "', 105) and convert(datetime, '" + hid_fence_end_datetime.Value + "', 105)) order by gps_id asc";

    dr = common.run_query(query, db, cm, dr, 0);
    if (dr.HasRows)
    {
        //To Build Fence Latitudes and Longitudes
        query = "select fence_id,fence_name,fence_type,landmark_latitude,landmark_longitude,fence_latitude,fence_longitude,fence_size from tracking_master_fences where domain_id = '" + domain_id1 + "' and fence_id = '" + hid_fence_id.Value + "' and is_active = '1'";

        dr2 = common.get_row(query, db2, cm2, dr2, 0);
        if (dr2.HasRows)
        {

            fence_id1 = dr2["fence_id"].ToString();
            fence_name1 = dr2["fence_name"].ToString();
            fence_type1 = dr2["fence_type"].ToString();
            landmark_latitude1 = common.make_float(dr2["landmark_latitude"].ToString());//fs_lat
            landmark_longitude1 = common.make_float(dr2["landmark_longitude"].ToString());//fs_long
            fence_latitude1 = common.make_float(dr2["fence_latitude"].ToString());//sec_lat
            fence_longitude1 = common.make_float(dr2["fence_longitude"].ToString());//sec_long
            fence_size1 = common.make_float(dr2["fence_size"].ToString());

        }
        dr2.Close();

        //Build POlygon Vertices
        if (fence_type1 == "4")
        {


            query = "select polygon_latitude,polygon_longitude from tracking_master_fence_polygons where fence_id = '" + hid_fence_id.Value + "' and domain_id = '" + domain_id1 + "'";
            dr1 = common.run_query(query, db1, cm1, dr1, 0);
            if (dr1.HasRows)
            {
                while (dr1.Read())
                {
                    vertices_x.Add(dr1["polygon_latitude"]);
                    vertices_y.Add(dr1["polygon_longitude"]);
                }
            }
            dr1.Close();
            points_polygon = vertices_x.Count;

        }

        //Create a Datatable of 14 rows
        dt_fence.Columns.Add("fence_id", typeof(string));
        dt_fence.Columns.Add("Date", typeof(string));
        dt_fence.Columns.Add("Speed", typeof(string));
        dt_fence.Columns.Add("Location", typeof(string));
        dt_fence.Columns.Add("landmark_latitude", typeof(string));
        dt_fence.Columns.Add("landmark_longitude", typeof(string));
        dt_fence.Columns.Add("fence_latitude", typeof(string));
        dt_fence.Columns.Add("fence_longitude", typeof(string));
        dt_fence.Columns.Add("latitude", typeof(string));
        dt_fence.Columns.Add("longitude", typeof(string));
        dt_fence.Columns.Add("fence_size", typeof(string));
        dt_fence.Columns.Add("fence_type", typeof(string));
        dt_fence.Columns.Add("fence_status", typeof(string));
        dt_fence.Columns.Add("object", typeof(string));


        while (dr.Read())
        {
            fence_status = "";
            float latitude = common.make_float(dr["latitude"].ToString());
            float longitude = common.make_float(dr["longitude"].ToString());

            if (fence_type1 == "1" || fence_type1 == "2")
            {

                if (((landmark_latitude1 * 100000) &lt; (latitude * 100000) &amp;&amp; (fence_latitude1 * 100000) &gt; (latitude * 100000)) &amp;&amp; ((landmark_longitude1 * 100000) &lt; (longitude * 100000) &amp;&amp; (fence_longitude1 * 100000) &gt; (longitude * 100000)))
                {
                    fence_status = "Inside";
                }
                else
                {
                    fence_status = "Outside";
                }

            }
            else if (fence_type1 == "3")
            {
                float ft = ((latitude * 100000) - (landmark_latitude1 * 100000));
                float st = ((longitude * 100000) - (landmark_longitude1 * 100000));

                float sqrt = common.make_float(Math.Sqrt((ft * ft) + (st * st)).ToString());

                if (fence_size1 &lt; sqrt)
                {
                    fence_status = "Out Side";
                }
                else
                {
                    fence_status = "In Side";
                }
            }
            else if (fence_type1 == "4")
            {
                longitude_x = common.make_float(dr["latitude"].ToString());
                latitude_y = common.make_float(dr["longitude"].ToString());

                int i = 0, j = 0, c = 0;
                for (i = 0, j = points_polygon - 1; i &lt; points_polygon; j = i++)
                {
                    float vertices_y_i_val = common.make_float(vertices_y[i].ToString());
                    float vertices_y_j_val = common.make_float(vertices_y[j].ToString());
                    float vertices_x_i_val = common.make_float(vertices_x[i].ToString());
                    float vertices_x_j_val = common.make_float(vertices_x[j].ToString());

                    if (((vertices_y_i_val &gt; latitude_y != (vertices_y_j_val &gt; latitude_y)) &amp;&amp;
(longitude_x &lt; (vertices_x_j_val - vertices_x_i_val) * (latitude_y - vertices_y_i_val) / (vertices_y_j_val - vertices_y_i_val) + vertices_x_i_val)))
                    {
                        c = 1;
                    }

                }

                if (c == 1)
                {
                    fence_status = "In Side";
                }
                else
                {
                    fence_status = "Out Side";
                }
            }

            dt_fence.Rows.Add(fence_id1, dr["added_date_time"], dr["speed"], dr["location"], landmark_latitude1, landmark_longitude1, fence_latitude1, fence_longitude1, latitude, longitude, fence_size1, fence_type1, fence_status, dr["object"]);

        }//End of while Loop

        //hid_ds_fence.Value = dt_fence.ToString();
        gridview_fence.DataSource = dt_fence;
        gridview_fence.DataBind();


    }
    dr.Close();

    fence_modalpopup.Show();

}
</code></pre>
