473,806 Members | 2,219 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Datagrid: click edit and all the rows disappear!

Most of this code comes from or follows the walkthrough (Using a
DataGrid Web Control to Read and Write Data). The problem is that as
soon as you click the Edit link, the data rows disappear, leaving you
with just the header row. I've figured out what's happening, but can't
figure out why.

Following along with the debugger, as soon as you click Edit, execution
goes to Page_Load, and at that point, before it even checks postback,
the dataset is empty. All the rows are gone. Anyone know why?

I suppose I could refill the dataset in Page_Load, but that leads to the
dreaded "Old Values" problem.

This doesn't make sense! Why would the bottom fall out of the dataset?
The structure is still there, all the column names and everything, but
the data itself is gone -- rows.count returns 0.

Thanks for any help!

Private Sub Page_Load(ByVal sender As System.Object, ByVal e ...
If Not Page.IsPostBack Then
OleDbDataAdapte r1.Fill(myDataS et1)
DataGrid1.DataB ind()
End If
End Sub

Private Sub DataGrid1_EditC ommand(ByVal source As Object, ByVal e ...
DataGrid1.EditI temIndex = e.Item.ItemInde x
DataGrid1.DataB ind()
End Sub

Private Sub DataGrid1_Cance lCommand(ByVal source As Object, ByVal e...
DataGrid1.EditI temIndex = -1
DataGrid1.DataB ind()
End Sub

Private Sub DataGrid1_Updat eCommand(ByVal source As Object, ByVal e...
Dim key As String = DataGrid1.DataK eys(e.Item.Item Index).ToString ()
Dim strA, strB, strC As String
Dim txt As TextBox
txt = CType(e.Item.Ce lls(1).Controls (0), TextBox)
strA = txt.Text
txt = CType(e.Item.Ce lls(2).Controls (0), TextBox)
strB = txt.Text
txt = CType(e.Item.Ce lls(3).Controls (0), TextBox)
strC = txt.Text

Dim r As myDataSet.XRow
r = myDataSet1.X.Fi ndByRecID(key)
r.A = strA
r.B = strB
r.C = strC
OleDbDataAdapte r1.Update(myDat aSet1)
DataGrid1.EditI temIndex = -1
DataGrid1.DataB ind()
End Sub
End Class

Nov 18 '05 #1
4 1477
Typically you only fill the DataSet once - the first Page_Load event.
After that the DataGrid will keep around the data it needs to
redisplay in the ViewState. Are you checking for rows in the DataSet
or data in the DataGrid on postback?

--
Scott
http://www.OdeToCode.com
I suppose I could refill the dataset in Page_Load, but that leads to the
dreaded "Old Values" problem.

This doesn't make sense! Why would the bottom fall out of the dataset?
The structure is still there, all the column names and everything, but
the data itself is gone -- rows.count returns 0.

Thanks for any help!

Private Sub Page_Load(ByVal sender As System.Object, ByVal e ...
If Not Page.IsPostBack Then
OleDbDataAdapte r1.Fill(myDataS et1)
DataGrid1.DataB ind()
End If
End Sub

Private Sub DataGrid1_EditC ommand(ByVal source As Object, ByVal e ...
DataGrid1.EditI temIndex = e.Item.ItemInde x
DataGrid1.DataB ind()
End Sub

Private Sub DataGrid1_Cance lCommand(ByVal source As Object, ByVal e...
DataGrid1.EditI temIndex = -1
DataGrid1.DataB ind()
End Sub

Private Sub DataGrid1_Updat eCommand(ByVal source As Object, ByVal e...
Dim key As String = DataGrid1.DataK eys(e.Item.Item Index).ToString ()
Dim strA, strB, strC As String
Dim txt As TextBox
txt = CType(e.Item.Ce lls(1).Controls (0), TextBox)
strA = txt.Text
txt = CType(e.Item.Ce lls(2).Controls (0), TextBox)
strB = txt.Text
txt = CType(e.Item.Ce lls(3).Controls (0), TextBox)
strC = txt.Text

Dim r As myDataSet.XRow
r = myDataSet1.X.Fi ndByRecID(key)
r.A = strA
r.B = strB
r.C = strC
OleDbDataAdapte r1.Update(myDat aSet1)
DataGrid1.EditI temIndex = -1
DataGrid1.DataB ind()
End Sub
End Class


Nov 18 '05 #2
Scott Allen <bitmask@[nospam].fred.net> wrote:
Typically you only fill the DataSet once - the first Page_Load event.
After that the DataGrid will keep around the data it needs to
redisplay in the ViewState.
Do you know if it does this automatically? Or is there some coding to do
to accomplish this?
Are you checking for rows in the DataSet or data in the DataGrid on
postback?


Well, the data is gone from both places. It's the same data, isn't it?
Or does the DataGrid actually make a copy?

Nov 18 '05 #3
On Fri, 02 Jan 2004 09:46:16 -0800, "tr****@sirius. com.no.more"
<us**@example.c om> wrote:
Scott Allen <bitmask@[nospam].fred.net> wrote:
Typically you only fill the DataSet once - the first Page_Load event.
After that the DataGrid will keep around the data it needs to
redisplay in the ViewState.


Do you know if it does this automatically? Or is there some coding to do
to accomplish this?


This happens automatically unless you have EnableViewState = false
somwhere in the code or in the ASPX.
Are you checking for rows in the DataSet or data in the DataGrid on
postback?


Well, the data is gone from both places. It's the same data, isn't it?
Or does the DataGrid actually make a copy?


The DataSet object will be empty for certain in Page_Load, but the
DataGrid should be reloaded with values kept in the ViewState on the
client.

You might want to look through the following article and compare code
to see what is different:

Walkthrough: Using a DataGrid Web Control to Read and Write Data
http://msdn.microsoft.com/library/de...dwritedata.asp

Hope this helps,

--
Scott
--
Scott
http://www.OdeToCode.com
Nov 18 '05 #4
Scott Allen <bitmask@[nospam].fred.net> wrote:
On Fri, 02 Jan 2004 09:46:16 -0800, "tr****@sirius. com.no.more"
<us**@example. com> wrote:
Scott Allen <bitmask@[nospam].fred.net> wrote:
Typically you only fill the DataSet once - the first Page_Load event.
After that the DataGrid will keep around the data it needs to
redisplay in the ViewState.
Do you know if it does this automatically? Or is there some coding to do
to accomplish this?


This happens automatically unless you have EnableViewState = false


Oh, right. That's something to check.
You might want to look through the following article and compare code
to see what is different:

Walkthrough: Using a DataGrid Web Control to Read and Write Data
http://msdn.microsoft.com/library/de...dwritedata.asp


Okay, thanks.

Nov 18 '05 #5

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

Similar topics

2
9931
by: Chris Plowman | last post by:
Hi all, I was wondering if anyone can help me with a really annoying problem I have been having. I made a derived datagrid class that will select the row when a user clicks anywhere on a cell (multi-select without modifier keys). I got that working fine, but I also wanted to keep rows selected after a sort, which I do by storing the row's id in an arraylist. The idea was to do the sort and then go back and re-select the rows with that...
2
3313
by: Alpha | last post by:
I have a window application. In one of the form, a datagrid has a dataview as its datasource. Initial filtering result would give the datavew 3 items. When I double click on the datagrid to edit the selected lie item at which case I would pop up a separate dialog box to do so, in the debugging code, the dataview.count would return 0. I get a error message because I tried to get values out of a dataview that holds 0 items. Does anyone...
3
4889
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
1
4347
by: Rick | last post by:
Hello all, I hope all is well with you. I am having a seriously difficult time with this problem. Allow me to set up the problem. I have a System.Web.UI.Page with the following controls (watch the layout, some have child controls):
0
473
by: Steve | last post by:
I have a datagrid that is created at run time DataGrid dgG = new DataGrid(); BoundColumn bcB; dgG.CellPadding = 5; dgG.CellSpacing = 0; dgG.GridLines = GridLines.Both; dgG.CssClass = "SectionTableLines"; dgG.DataKeyField = "PlanWorkOrderID";
4
2730
by: skOOb33 | last post by:
I successfully autosized the columns and rows on my Datagrid, and am now facing another issue. Having the sorting ability by clicking the column headers is key, but when I do that, it resizes all my rows back to their defaults. I populate the datagrid, resize it accordingly and it works fine...just when I click the headers is when it messes up. It would be fine if I could run my autosizing again after the sorting is done since there...
7
3230
by: julian.tklim | last post by:
Hi, I need to build an editable Datagrid with add & delete buttons on each row using javascript. DataGrid need not be pre-populated with values. To make the thing complicated, one of the column need to be a date picker field. I know things will be easier with ASPX datagrid.
9
2734
by: rn5a | last post by:
A Form has a DataGrid which displays records from a SQL Server 2005 DB table. Users can modify the records using this DataGrid for which I am using EditCommandColumn in the DataGrid. This is the code: <script runat="server"> Dim sqlConn As New SqlConnection(".....") Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs) If Not (Page.IsPostBack) Then FillDataGrid()
1
2546
by: johnlim20088 | last post by:
Hi, Hi, i have a datagrid in my mypage.aspx, I used the Bound column consisted of Edit, Save, Cancel, button. When I press edit, my datagrid change to editable mode, which the Save and Cancel Button appear, edit button disappear. When I click Cancel, the Save and Cancel button disappear, and the edit button appear again. This is working fine.
0
10617
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9186
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7649
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6876
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5545
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5678
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4328
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3849
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3008
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.