Avatar of toooki
toooki
 asked on

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">
        </asp:GridView>

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;
            grid1.DataBind();

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..
thanks.


.NET ProgrammingASP.NET

Avatar of undefined
Last Comment
toooki

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Kaushal Arora

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
toooki

ASKER
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">
        </asp:GridView>

Is there any alternate design that will let me update the dataSet (NOT bound directly to a database table) via a web form..?
Kaushal Arora

Is your columns same every time or they will b changing every time you bind the grid with DataSet.
toooki

ASKER
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)
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
SOLUTION
Kaushal Arora

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
toooki

ASKER
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