Hi
I have below Gridview & i want only last column Date to be editable
Code
C#
DataTable BookPlanningResult = sQLUtility.GeBookPlanningRecommendation(vRpl, 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.Columns[grdPlanning.Columns.Count - 1].ReadOnly = false;
grdPlanning.DataBind();
}Thanks

Tuhin PaulRank #7 · 71.9K reputationPosted May 1, 2023, 2:47 PM EDT
See the code:
protected void grdPlanning_RowDataBound(object sender, GridViewRowEventArgs e) { if (e.Row.RowType == DataControlRowType.DataRow) { // Set ReadOnly property to true for all columns except the last column for (int i = 0; i < e.Row.Cells.Count - 1; i++) { e.Row.Cells[i].Attributes.Add("ReadOnly", "true"); } // Set ReadOnly property to false for the last column e.Row.Cells[e.Row.Cells.Count - 1].Attributes.Remove("ReadOnly"); } }You also need to add the OnRowDataBound event to the GridView control:
This code will set the ReadOnly attribute to true for all the columns except for the last column in each row of the GridView, which will be set to false. This will make only the last column editable.
Vishal YelveRank #178 · 13.6K reputationPosted Apr 30, 2023, 4:00 AM EDT
Hi refer below links
https://stackoverflow.com/questions/14935765/editing-one-column-of-data-grid-view
https://www.aspsnippets.com/Articles/Make-one-Single-Specific-column-Editable-in-ASPNet-GridView.aspx
Tuhin PaulRank #7 · 71.9K reputationPosted May 1, 2023, 2:46 PM EDT
To make only the last column in the GridView editable, you can set the ReadOnly property of all the columns to true except for the last column.