473,486 Members | 2,131 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Datatable as Gridview datasource

Hi,
i have a "simple" problem with gridview, please help me :)
i want to have gridview which is binded to a datatable (or a dataset).
i can show the data from the dataset in the gridview and i can start
editing the data, but when i click update i loose my new values. I want
this values to be saved in datatable (not straight to database with
sqldatasource - i tried this and it worked great), i tried to do this
task with objectdatasource but i couldn't make it work :(
can anyone post a little example of how to do this? (i'm searching
googles for a week and still found nothing )

Thanks
Jan Zascinski

Dec 27 '05 #1
1 9154
Two ways I can think of to accomplish this:

1. Use the old style DataBind() with a DataSource that is set to a
DataTable. You will have to subscribe to a number of the events on the
GridView such as Editing, Deleting and Selecting and make the changes to
your base DataTable yourself. Using DataBind with a DataSource (not a
DataSourceID) will only allow for one way databinding. The GridView will
read and display your DataTable but you will have to make the updates
yourself.

2. Use an ObjectDataSource that points to your own Data Access layer class
that in turn updates a DataTable that you maintain.

Both methods will require that you somehow persist your data in the
DataTable between postbacks. This is normally done by writing back to a
database but you don't want to do that so you will have to save it somewhere
else which could include application state, session state or in a server
cache. All of these come with their own set of unique advantages and
disadvantages.

Hope this helps.

--

Andrew Robinson
www.binaryocean.com
www.bellinghamdotnet.org
<j.*********@interia.pl> wrote in message
news:11**********************@o13g2000cwo.googlegr oups.com...
Hi,
i have a "simple" problem with gridview, please help me :)
i want to have gridview which is binded to a datatable (or a dataset).
i can show the data from the dataset in the gridview and i can start
editing the data, but when i click update i loose my new values. I want
this values to be saved in datatable (not straight to database with
sqldatasource - i tried this and it worked great), i tried to do this
task with objectdatasource but i couldn't make it work :(
can anyone post a little example of how to do this? (i'm searching
googles for a week and still found nothing )

Thanks
Jan Zascinski

Dec 27 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
1035
by: Matthew | last post by:
I have a SQLDataSource object declared in my ASPX page. <asp:SqlDataSource ID="SqlDataSource1" runat="server" etc.. etc.. /> I pipe that query into a GridView, but I also want to populate the...
0
4300
by: Elmo Watson | last post by:
OK - main gridview - gvTV In one column - I have another Gridview - gvTRPTV - function: Public Function AddTRPRow() As DataTable dtHeader = CType(ViewState("Header"), DataTable) If dtHeader...
4
26680
by: Tomasz Jastrzebski | last post by:
Hello Everyone, I have a GridView control bound to a plain DataTable object. AutoGenerateEditButton is set to true, Edit button gets displayed, and RowEditing event fires as expected.
1
2738
by: weird0 | last post by:
I have created a GridView and dynamically added data to it by creating a DataTable(as advised) and bound it with a reader. Then, assigned the DataSource of GridView to DataTable. But even that aint...
2
3017
by: chike_oji | last post by:
Please can someone help me. I am writing a web application, that allows for the upload of an excel sheet into the database. I have an upload button and a save button. The upload button allows...
3
7380
by: ASPnewb1 | last post by:
I am currently filling a dataTable then adding this table to a dataset, setting the dataset to the Gridview's datasource. If I set the Gridview to generate columns automatically it will fill the...
0
1641
by: tina2626 | last post by:
I m using this code in C#.net, for dynamic creation of GridView without using DB. <CODE> protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) {...
0
2363
by: Andy B | last post by:
I have the following gridview. There are 2 other textBoxes and a button on the page as well. When somebody puts text into the 2 textBoxes and presses the add button, it puts the values of those...
0
1454
by: user1980 | last post by:
Hello Can somebody please help me with the paging in a grid-view. please find my code below SqlDataAdapter sda = new SqlDataAdapter(); DataTable dt = new DataTable(); ...
0
6964
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7126
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7175
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
7330
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
1
4865
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4559
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3070
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3070
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
262
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.