How to save, edit, and read data (in code behind) from an unbound Gridview in ASP.NET

Posted on 2010-01-08
Last Modified: 2012-05-08
Hi experts,

I am having some issues trying to save and edit data from an unbound gridview.  Is this even possible?
Here's the scenario.  I populate a gridview in VS2008 with a dataset and datatable which I create programmatically
on Page_Load of the main page.  This grid contains a listing of the fieldnames from an xsd fille that changes based
on what report a user selects from a hard-coded folder path.  This grid also contains sorting options for sorting
any of the fields (given a numeric #), whether or not to include a given field on a report, and whether or not sorting
should occur in Ascending or Descending order.  The population of this grid with field names is fine and Edit/Update/Cancel
links are visible.  My problem is in obtaining the values after the user hits update so that I can save it to the in-memory
recordset and then re-bind the grid with the new data.  In this way I can build a dynamic SQL statement to build a
query for a report which will then get rendered via the in memory dataset.  Does anyone have any concrete examples
that actually work or give me some links that will actually help me out?  

I have tried to get the controls data via findcontrols at various levels in the object but I still seem to get nothing

Question by:sharizod
    LVL 10

    Accepted Solution

    Please try the following link.

    Unbound GridView
    LVL 1

    Author Comment

    Thanks Ramesh!  I tried creating the fields dynamically before and the controls would end up being named random names (ctl09, ctl10 etc..) which wasn't working too well.  The templated fields did the trick, although in the example, in the html, I found that I had to use '<%# Container.DataItem("FieldName") %>' instead of '<%# Bind("FieldName") %>' which was throwing errors at runtime.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Better Security Awareness With Threat Intelligence

    See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

    A Change in PHP Behavior with Session Write Short Circuit ( (Winter 2014)** With the release of PHP 5.6 the session handler changed in a way that many think should be considered a bug.  See the note …
    What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
    This video teaches users how to migrate an existing Wordpress website to a new domain.
    This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA.…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now