Hi
I have below code & i want to make Date Column editable.
SQLUtility sQLUtility = new SQLUtility();
DataTable BookPlanningResult = sQLUtility.GeBookPlanningRecommendation(BookCollection, StudentCollection).Tables[0];
if (BookPlanningResult != null)
{
DataColumn Remarks = new DataColumn("Remarks", typeof(string));
BookPlanningResult.Columns.Add(Remarks);
DataColumn Dates = new DataColumn("Date", typeof(DateTime));
BookPlanningResult.Columns.Add(Dates);
grdPlanning.DataSource = BookPlanningResult;
grdPlanning.DataBind();
}
Thanks
Ramco RamcoPosted May 1, 2023, 2:38 AM
Hi
DataControlField does not contain a definition for ReadOnly
int lastColumnIndex = BookPlanningResult.Columns.Count - 1;
grdPlanning.Columns[lastColumnIndex - 1].ReadOnly = false;
Thanks
Ramco RamcoPosted Apr 26, 2023, 11:11 AM
Hi
It is giving message 'DataControlField does not contain a definition for ReadOnly.
Thanks
Naimish MakwanaPosted Apr 26, 2023, 11:05 AM
If the "Date" column is always the last column in the GridView, you can use the "Columns.Count" property to get the index of the last column and make it editable. Here's how you can modify the code to achieve this:
if (BookPlanningResult != null) { DataColumn Remarks = new DataColumn("Remarks", typeof(string)); BookPlanningResult.Columns.Add(Remarks); DataColumn Dates = new DataColumn("Date", typeof(DateTime)); BookPlanningResult.Columns.Add(Dates);
grdPlanning.DataSource = BookPlanningResult;
int lastColumnIndex = grdPlanning.Columns.Count - 1;
grdPlanning.Columns[lastColumnIndex].ReadOnly = false; // Set the ReadOnly property to false for the last column
grdPlanning.DataBind();
}
Ramco RamcoPosted Apr 26, 2023, 11:02 AM
Hi naimish
Columns will be dynamic. But it will be the Last Column
Thanks
Naimish MakwanaPosted Apr 26, 2023, 11:00 AM
To make the "Date" column editable, you can either use the index of the column in the collection or find the column by name using the LINQ extension method "FirstOrDefault()". Here are two possible ways to modify the code:
// Option 1: use the column index grdPlanning.Columns[1].ReadOnly = false; // assuming that "Date" is the second column in the GridView
// Option 2: use LINQ to find the column by name var dateColumn = grdPlanning.Columns.Cast().FirstOrDefault(col => col.Name == "Date"); if (dateColumn != null) { dateColumn.ReadOnly = false; }
Ramco RamcoPosted Apr 26, 2023, 10:56 AM
Hi
It is gicing error - Cannot convert from string to int
grdPlanning.Columns["Date"].ReadOnly = false;
Naimish , second option can be How to add edit button & in Modal Popup user should fill Date & it should reflect in that row Date column.
Thanks
Naimish MakwanaPosted Apr 26, 2023, 10:43 AM
Assuming that you are using a GridView control to display the data, you can make the "Date" column editable by setting the "ReadOnly" property of the corresponding column in the GridView to "false". Here's how you can modify the code:
Thanks