Hi
I have below code & i want to loop thru Gridview which have value in Date column i want to add those records
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();
}
Thanks
Tuhin PaulPosted May 4, 2023, 12:03 PM
The code you provided is creating a DataTable `dt` using data returned from a function `GeBookPlanningRecommendation`. The DataTable `dt` is then used as a data source for a GridView `grdPlanning`, which is then bound to display the data. The DataTable `dt` is created with two additional columns, "Remarks" and "Date". The "Remarks" column is of type string, and the "Date" column is of type DateTime. The "Date" column is editable in the GridView. You want to get the rows from the GridView that have values in the "Date" column and add those rows to the DataTable `dt`. To do this, you need to loop through the GridView rows, check if the "Date" column has a value, and if so, add the row to the DataTable `dt`. You can do this by adding the following code after the GridView is bound:
This code loops through each row in the GridView, tries to parse the value in the second cell (the "Date" column) to a DateTime object, and if successful, creates a new DataRow for the DataTable `dt` and adds the "Remarks" and "Date" values from the GridView row to the new DataRow. The new DataRow is then added to the DataTable `dt`.
Tuhin PaulPosted May 4, 2023, 12:00 PM
You can loop through the rows of the GridView to check if the "Date" column has a value and then add those rows to a new DataTable.
Jignesh KumarPosted May 4, 2023, 11:19 AM
You can try this link,
Row by row
https://www.c-sharpcorner.com/blogs/insert-data-into-database-from-gridview-in-asp-net1
At one go save all records,
https://www.c-sharpcorner.com/UploadFile/0c1bb2/insert-bulk-records-into-database-using-Asp-Net-C-Sharp/
Ramco RamcoPosted May 4, 2023, 11:00 AM
Hi JIgnesh
If u see i have Date field which is Editable. User will fill values in some of the rows. Now i want to get those records from Gridview which have values in Date & Add those records in table
Thanks
Jignesh KumarPosted May 4, 2023, 10:52 AM
what values you are getting in this dt ? from this result you want to create new datatable and bind in gridview ?
Ramco RamcoPosted May 4, 2023, 10:49 AM
Hi Jignesh
I want to add Data in table of those rose which have values in Date column
Thanks
Jignesh KumarPosted May 4, 2023, 10:21 AM
Hello Ramco,
please use this one,