Hi
In below code i want SessionDate to be editable in all rows
C#
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("SessionDate", typeof(string));
dt.Columns.Add(Dates);
grdPlanning.DataSource = dt;
grdPlanning.DataBind();
}Thanks

Rajkiran SwainRank #165 · 14.4K reputationPosted May 6, 2023, 10:15 AM EDT
Try like this and add your additional column in the grid.
protected void grdPlanning_RowUpdating(object sender, GridViewUpdateEventArgs e) { GridViewRow row = grdPlanning.Rows[e.RowIndex]; string bookId = grdPlanning.DataKeys[e.RowIndex].Value.ToString(); TextBox txtSessionDate = (TextBox)row.FindControl("txtSessionDate"); string sessionDate = txtSessionDate.Text; // Update the "SessionDate" field in the database SQLUtility sQLUtility = new SQLUtility(); sQLUtility.UpdateSessionDate(bookId, sessionDate); // Rebind the GridView to reflect the changes grdPlanning.EditIndex = -1; BindGrid(); }BindGrid code as below
-------------------------
//Page Load SQLUtility sQLUtility = new SQLUtility(); DataTable dt = sQLUtility.GeBookPlanningRecommendation(HRpl, BookCollection, StudentCollection).Tables[0]; if (dt != null) { grdPlanning.DataSource = dt; grdPlanning.DataBind(); }Rajkiran SwainRank #165 · 14.4K reputationPosted May 5, 2023, 10:51 AM EDT
// Create a DataTable with the required columns DataTable dt = new DataTable(); dt.Columns.Add("SessionDate", typeof(DateTime)); dt.Columns.Add("Remarks", typeof(string)); // Populate the DataTable with data dt.Rows.Add(DateTime.Today.AddDays(1), "Row 1 Remarks"); dt.Rows.Add(DateTime.Today.AddDays(2), "Row 2 Remarks"); dt.Rows.Add(DateTime.Today.AddDays(3), "Row 3 Remarks"); // Bind the DataTable to the GridView grdPlanning.DataSource = dt; // Make the "SessionDate" column editable GridViewColumn sessionDateColumn = grdPlanning.Columns["SessionDate"]; sessionDateColumn.ReadOnly = false; // Bind the GridView grdPlanning.DataBind();Ramco RamcoRank #462 · 5.4K reputationPosted May 5, 2023, 11:00 AM EDT
Hi RajKiran
It is giving error - The type or namespace name GridViewColumn could not be found
GridViewColumn sessionDateColumn = grdPlanning.Columns["SessionDate"];
Thanks
Rajkiran SwainRank #165 · 14.4K reputationPosted May 5, 2023, 11:11 AM EDT
To make the "SessionDate" column editable in all rows of a GridView, you can set the `ReadOnly` property of the corresponding column in the `GridView.Columns` collection to `false`. Here's an example:
```
// Bind the DataTable to the GridView
grdPlanning.DataSource = dt;
grdPlanning.DataBind();
// Make the "SessionDate" column editable
GridViewColumn sessionDateColumn = grdPlanning.Columns["SessionDate"];
sessionDateColumn.ReadOnly = false;
```
In the above code, we first bind the DataTable `dt` to the GridView `grdPlanning`. Then, we get the `GridViewColumn` corresponding to the "SessionDate" column and set its `ReadOnly` property to `false`, which makes the column editable in all rows of the GridView.
Ramco RamcoRank #462 · 5.4K reputationPosted May 5, 2023, 11:26 AM EDT
Hi RajKiran
It is giving error - The type or namespace name GridViewColumn could not be found
GridViewColumn sessionDateColumn = grdPlanning.Columns["SessionDate"];
Thanks
Rajkiran SwainRank #165 · 14.4K reputationPosted May 5, 2023, 11:28 AM EDT
Is it windows or asp.net ?Ramco RamcoRank #462 · 5.4K reputationPosted May 5, 2023, 11:30 AM EDT
asp.net
Rajkiran SwainRank #165 · 14.4K reputationPosted May 5, 2023, 11:33 AM EDT
SQLUtility sQLUtility = new SQLUtility(); DataTable dt = sQLUtility.GeBookPlanningRecommendation(HRpl, BookCollection, StudentCollection).Tables[0]; if (dt != null) { grdPlanning.DataSource = dt; grdPlanning.DataBind(); }Ramco RamcoRank #462 · 5.4K reputationPosted May 5, 2023, 11:38 AM EDT
Hi Rajkiran
I have dynamic columns . These 2 columns i have added after the Dynamic columns. Code shared above. I have autogenerate columns = true
I want SessionDate to be editable only.
Thanks
Rajkiran SwainRank #165 · 14.4K reputationPosted May 5, 2023, 11:45 AM EDT
In order to make the "SessionDate" column editable, you can use a TemplateField instead of a BoundField. Here's an example of how you can modify the code to achieve this:
protected void grdPlanning_RowUpdating(object sender, GridViewUpdateEventArgs e) { DataTable dt = sQLUtility.GeBookPlanningRecommendation(HRpl, BookCollection, StudentCollection).Tables[0]; GridViewRow row = grdPlanning.Rows[e.RowIndex]; TextBox txtSessionDate = (TextBox)row.FindControl("txtSessionDate"); dt.Rows[row.DataItemIndex]["SessionDate"] = txtSessionDate.Text; sQLUtility.UpdateBookPlanningRecommendation(dt); grdPlanning.EditIndex = -1; BindGrid(); }Ramco RamcoRank #462 · 5.4K reputationPosted May 5, 2023, 11:58 AM EDT
Hi RajKiran
I have attached image . Textbox should appear on right side of Gridvew SessionDate column. It is creating another column
Rajkiran SwainRank #165 · 14.4K reputationPosted May 5, 2023, 12:02 PM EDT
Please send the full code with HTML.
Ramco RamcoRank #462 · 5.4K reputationPosted May 5, 2023, 12:05 PM EDT
Hi RajKiran
Pls find the code. AutogenerateColumns = true. I want SessionDate only to be editable so that user can enter Date
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("SessionDate", typeof(string)); dt.Columns.Add(Dates); grdPlanning.DataSource = dt; grdPlanning.DataBind(); }Thanks