Hi
I have below Data for Gridiew. After last columa Date i want to add Edit Image
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.DataBind();
}Thanks

Rajkiran SwainRank #165 · 14.4K reputationPosted Apr 29, 2023, 11:44 AM EDT
protected void grdPlanning_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "Edit") { int rowIndex = Convert.ToInt32(e.CommandArgument); // perform edit operation } }Tuhin PaulRank #7 · 71.9K reputationPosted May 1, 2023, 2:42 PM EDT
To add an edit image after the last column in the GridView, you can use a TemplateField with an Image control that has a click event to handle the edit action.
Tuhin PaulRank #7 · 71.9K reputationPosted May 1, 2023, 2:42 PM EDT
In the code behind, you can handle the click event of the Image control to perform the edit action
protected void imgEdit_Click(object sender, ImageClickEventArgs e) { // Get the row where the edit button was clicked GridViewRow row = ((ImageButton)sender).NamingContainer as GridViewRow; // Retrieve the data from the row using row.FindControl("ControlID") string column1 = (row.FindControl("lblColumn1") as Label).Text; string column2 = (row.FindControl("lblColumn2") as Label).Text; string column3 = (row.FindControl("lblColumn3") as Label).Text; // ... and so on // Perform the edit action using the retrieved data // ... }In the GridView, the BoundFields should be replaced with the actual column names from your DataTable, and the control IDs in row.FindControl should match the IDs of the controls in the ItemTemplate.