First, we’ll implement a method to databind the Grid View, which will be called whenever databinding needs to be performed.
For instance: So the questions is how do you get the database table field name by index via code behind?
I too have been searching for this and all the "answers" that I've seen are not the answers I think some of us are really looking for.
The asker of the question wanted to get the database field name by index.
I've seen a number of "answers" which only provide the text in the selected row of a gridview, or the header text which both do not answer the question that was asked... If you were going to do audits of updates in a system and wanted to compare old values and new values and only update if they change and want to indicate which field was updated how do you show the database table field name at the index of the loop.
First, I load up some data: After that, I’m doing some work to make my Grid View look beautifull, adding all columns by hand.
But for this demo, I’ll show you the simple version, that also doesn’t work 🙂Let’s bind the data to our Grid View and have it autogenerate our columns, as well as an edit button.When we edit a row in our Grid View and press the “Update” button, at some time it’s received in the Row Updating method.But as I noted in the comments in that method, some collections that should contain the columns (names, old values and new values) are always empty. And the Row Updated method is never even touched!!! NET Forums that I need to use a Data Source control.All the mentioned methods I've seen here are not bullet proof references to a database tables field name.Data Table dt = new Data Table(); foreach(Data Control Field Header Cell column in your Gridview. Cells) //Make sure you do all this after your Gridview.For a while now I’m trying to figure out why my method, triggered by the Grid View.