Link to home
Start Free TrialLog in
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.


ASKER CERTIFIED SOLUTION
Avatar of Kaushal Arora
Kaushal Arora
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of toooki
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..?
Is your columns same every time or they will b changing every time you bind the grid with DataSet.
Avatar of 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)
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of 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