Hi
How to hide GridView column if Autogenerate columns = true. Below is my code. But i want to read its value
SQLUtility sQLUtility = new SQLUtility();
DataTable dt = sQLUtility.GeBookPlanningRecommendation(vRpl, BookCollection, StudentCollection).Tables[0];
if (dt != null)
{
//DataColumn Remarks = new DataColumn("Remarks", typeof(string));
//dt.Columns.Add(Remarks);
DataColumn Dates = new DataColumn("Date", typeof(DateTime));
dt.Columns.Add(Dates);
grdPlanning.DataSource = dt;
grdPlanning.DataBind();
}
Thanks
Tuhin PaulPosted May 3, 2023, 6:30 PM
If you want to hide a specific column in a GridView with AutoGenerateColumns set to true, you can use the DataBound event of the GridView to loop through the columns and set the Visible property to false for the column you want to hide.
See the code:
In this example, the column index to hide is set to 3, but you can replace it with the actual column index you want to hide. The code loops through each row of the GridView and sets the Visible property of the cell in the specified column index to false. The same is done for the header row to hide the column header. You can add this event handler method to your code behind file and attach it to the DataBound event of the GridView control by adding the following attribute to the GridView tag in your markup:
This will call the grdPlanning_DataBound method every time the GridView is databound and hide the specified column.
Tuhin PaulPosted May 3, 2023, 6:29 PM
To hide a specific column in a GridView control when AutoGenerateColumns property is set to true, you can modify your existing code slightly to add an extra condition before binding the DataSource.