[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2011-10-08
6
Medium Priority
?
334 Views
Last Modified: 2013-12-16
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.


0
Comment
Question by:toooki
  • 3
  • 3
6 Comments
 
LVL 12

Accepted Solution

by:
Kaushal Arora earned 1980 total points
ID: 36937903
0
 

Author Comment

by:toooki
ID: 36937933
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..?
0
 
LVL 12

Expert Comment

by:Kaushal Arora
ID: 36937973
Is your columns same every time or they will b changing every time you bind the grid with DataSet.
0
NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

 

Author Comment

by:toooki
ID: 36938016
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)
0
 
LVL 12

Assisted Solution

by:Kaushal Arora
Kaushal Arora earned 1980 total points
ID: 36938044
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?
0
 

Author Comment

by:toooki
ID: 36938853
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

0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
With just a little bit of  SQL and VBA, many doors open to cool things like synchronize a list box to display data relevant to other information on a form.  If you have never written code or looked at an SQL statement before, no problem! ...  give i…
Suggested Courses
Course of the Month18 days, 14 hours left to enroll

834 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