Editable Gridview to edit underlying DataTable in ASP.NET (C#)

In my ASP.NET code in C# (VS 2008) I have created a gridView and here is the .aspx code:

        <asp:GridView ID="grid1" runat="server">

In aspx.cs code I have created a DataTable via program code and I could bind to the GridView by this code:

            grid1.DataSource = dsOut;

dsOut above has variable number of columns and unknown column names (names of the columns are determined in the program code).
The content shows in the GridView correctly. How can I make the GridView  editable so that after the Submit button is pressed --

 protected void btn1_Click(object sender, EventArgs e)
        DataTable dt = (DataTable)grid1.DataSource;

The above works. I can get the data in "dt" but all I need it seems to make the GridView editable..

Who is Participating?
toookiAuthor Commented:
Thank you.
I have used editable gridview before but there I used the bound source (bound to a database table) -- there Edit/Update was fairly easy (as they way mentioned in the above links...).

But the GridView is bound to a dataSet.  

I cannot provide the column names:

        <asp:GridView ID="grid1" runat="server">

Is there any alternate design that will let me update the dataSet (NOT bound directly to a database table) via a web form..?
Kaushal AroraTechnical AnalystCommented:
Is your columns same every time or they will b changing every time you bind the grid with DataSet.
Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

toookiAuthor Commented:
The number of columns will be the same. But the column names are not like Id/Name/Address..
The column names are like Feb022011, Feb092011, Feb162011, Mar032011, etc.
But yes the column names will be the same...
(I get the column names by somewhat transposing a table from the database -- so the column names are like this)
Kaushal AroraConnect With a Mentor Technical AnalystCommented:
That means if you will be filling your dataset for month of apr, may or august the column names can change i suppose for the gridview to show but the display will be like May022011 etc.

Is this so?
toookiAuthor Commented:
Thank you.
Yes that is right..I obtain the values say May022011 from a date field from the database table and convert to char string like May022011 .

I could fill the dataset without issues.

The dataset looks like:
Id          02Feb2011 09Feb2011 06Apr2011 20Jun2011
abc1     10               15                20              5
abc2      15               7                  9               70
abc2       8                2                  0               11

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.