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
Ramco RamcoPosted May 8, 2023, 8:03 AM
Hi Amit
In Add I have written below code but it is returning Null . I have entered date in this row
Thanks
Ramco RamcoPosted May 8, 2023, 7:40 AM
Hi Amit
I have below code . Even if enter Data in one of the rows it is not retreiving. Add functionality is not able to retreive TextBox value.
Thanks
Amit MohantyPosted May 8, 2023, 7:16 AM
Try this
Ramco RamcoPosted May 8, 2023, 6:28 AM
Hi AMit
When i write this line i get below error - e.Row.DataItem = txtSessionDate;
DataBinding System.Web.UI.WebControls.TextBox does not contain a property with the name Remarks.
Thanks
Ramco RamcoPosted May 8, 2023, 6:20 AM
Hi AMit
o.k But how in below code i will get SessionDate value in a variable
Thanks
Amit MohantyPosted May 8, 2023, 5:53 AM
The above code creates a new
TextBoxcontrol, sets its properties, and adds it to theGridViewrow. But, when you try to access thisTextBoxcontrol later in the code using theFindControlmethod, it returnsnull. Because theFindControlmethod only searches for controls that were added to the page declaratively, i.e., controls that were defined in the .aspx markup. But you are adding theTextBoxcontrol dynamically in code-behind, it is not part of the page's control hierarchy, andFindControlcannot find it.Ramco RamcoPosted May 8, 2023, 5:41 AM
Hi AMit
If i am adding Textbox Control then why it is showing NULL.
Thanks
Amit MohantyPosted May 8, 2023, 5:38 AM
You can check if
txtSessionDateis not null before attempting to set itsEnabledproperty.