Ramco Ramco

Ramco Ramco

  • 442
  • 3.4k
  • 528.5k

Object reference not set to an instance of the Object

May 8 2023 5:24 AM

Hi

  On this line i am getting above error - txtSessionDate.Enabled = false;

protected void gr_RowDataBound(object sender, GridViewRowEventArgs e)
{
    try
    {
        if (e.Row.RowType != DataControlRowType.DataRow)
            return;
        e.Row.Cells[0].HorizontalAlign = HorizontalAlign.Center;

        TextBox txtSessionDate = new TextBox();
        txtSessionDate.Text = "";
        txtSessionDate.CssClass = "form-control daterange-single";
        e.Row.Cells[10].Controls.Add(txtSessionDate);
        e.Row.Cells[10].HorizontalAlign = HorizontalAlign.Center;

        txtSessionDate = (TextBox)e.Row.FindControl("txtSessionDate");
        string Remark = DataBinder.Eval(e.Row.DataItem, "Remarks").ToString(); 
        if (Remark == "Done" || Remark == "Scheduled")
        {
            txtSessionDate.Enabled = false;
        }
    }
}
------------------
SQLUtility sQLUtility = new SQLUtility();
DataTable dt = sQLUtility.GeBookPlanningRecommendation(HRpl, BookCollection, StudentCollection).Tables[0];
if (dt != null)
{
    DataColumn Remarks = new DataColumn("Remarks", typeof(string));
    dt.Columns.Add(Remarks);
    DataColumn Dates = new DataColumn("SessionDt", typeof(string));
    dt.Columns.Add(Dates);
}

Thanks


Answers (8)