title: How to bind the label in GridView in asp.net
body: <p>I am using Gridview to display my details </p>
  
  <pre><code> &lt;asp:GridView ID="gvDetails" runat="server"&gt;
                  &lt;HeaderTemplate&gt;
                      &lt;asp:Label ID="Details" runat="server" Text="Remarks"&gt;&lt;/asp:Label&gt;
                      &lt;/HeaderTemplate&gt;
                  &lt;ItemTemplate&gt;
  
                  &lt;asp:Label ID="remarks" runat="server"&gt;&lt;/asp:Label&gt;
                  &lt;/ItemTemplate&gt;
  &lt;/asp:GridView&gt;
  </code></pre>
  
  <p>Now from the backend c# i am fetching from database and displaying</p>
  
  <pre><code>var regiondata = (from rm in db.RegionMasters select new { rm.regionName,rm.remarks,rm.regionId }).ToList();
            if (regiondata.Count &gt; 0)
            {
              foreach (var region in regiondata)
              {                    
                  string z = region.remarks.ToString().Substring(0, 5);    
                  ((Label)gvDetails.FindControl("remarks")).Text = z.ToString();    
                  gvDetails.DataSource = region;
                  gvDetails.DataBind();
  
               }
  
             }
  </code></pre>
  
  <p>so to display in the label thats inside the gridview i am using ((Label)gvDetails.FindControl("remarks")).Text = z.ToString(); but it keeps showing me "object reference not set to an instance of an object" </p>