Ramco Ramco

Ramco Ramco

  • 445
  • 3.4k
  • 530.4k

Object reference not set to an instance of the Object

May 8 2023 6:38 AM

Hi

protected void lnkAdd_Click(object sender, EventArgs e)
{
    try
    {
        //string sessionDate = "";
        Boolean success = false;

        BALGroup objGroup = new BALGroup();
        Group Result = objGroup.GetGroupDetail(Convert.ToInt32(hdfGroupId.Value));

        foreach (GridViewRow gr in grdPlanning.Rows)
        {
            if (gr.RowType == DataControlRowType.DataRow)
            {
                string sessionDate = gr.DataItem.ToString();
                if (sessionDate != null)
                {}
            }
        }
    }
}

--------------
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;
        

        string Remark = DataBinder.Eval(e.Row.DataItem, "Remarks").ToString(); 
        if (Remark == "Done" || Remark == "Scheduled")
        {
            if (txtSessionDate != null)
            {
                txtSessionDate.Enabled = false;
            }
        }
        e.Row.DataItem = txtSessionDate;
    }
}

Thanks


Answers (3)