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
Mohamed Azarudeen ZPosted May 9, 2023, 5:45 PM
Ramco if i may
The code line
e.Row.DataItem = txtSessionDate;is trying to assign a value to theDataItemproperty of aGridViewRowobject, which is represented by the variablee.Row.Ramco RamcoPosted May 8, 2023, 8:09 AM
Hi Naimish
What does this line does
e.Row.DataItem = txtSessionDate;
Thanks
Naimish MakwanaPosted May 8, 2023, 7:07 AM
The error "Object reference not set to an instance of the object" typically occurs when you try to use an object that has not been instantiated. In the code you provided, the error could be caused by several factors, including:
The variable "gr.DataItem" in the lnkAdd_Click method may be null, causing an exception when ToString() method is called.
The txtSessionDate control may not have been initialized in the gr_RowDataBound method.
The DataItem property of the GridViewRowEventArgs parameter in the gr_RowDataBound method may be null, causing an exception when it is accessed.
To fix the issue, you could add some null checks before using the objects, like the following:
Thanks