Hi
I have below code & i want to loop thru Gridview which have value in Date column i want to get Remarks column value also stored in variable
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("Date", typeof(DateTime));
dt.Columns.Add(Dates);
grdPlanning.DataSource = dt;
grdPlanning.DataBind();
}
Rajkiran SwainPosted May 4, 2023, 11:39 AM
Tuhin PaulPosted May 4, 2023, 12:10 PM
Here is the code code that loops through the GridView and retrieves the Remarks column value for each row that has a value in the Date column.
We first add the Remarks and Dates columns to the data table before binding it to the GridView. Then, we loop through the GridView rows and retrieve the Remarks column value for each row that has a value in the Date column. We store the remarks values in a string variable.
Tuhin PaulPosted May 4, 2023, 12:08 PM
To loop through the GridView and get the Remarks column value stored in a variable, you can use the following code:
In this code, the `foreach` loop is used to iterate through each row in the GridView. The condition checks if the second column (index 1) contains a valid date value. If it does, the `remarks` variable is assigned the value of the third column (index 2), which is the Remarks column. You can then perform any desired operations on the `remarks` variable.