473,505 Members | 15,212 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
OleDbDataAdapter1.Fill(myDataSet1)
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e ...
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e...
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e...
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim strA, strB, strC As String
Dim txt As TextBox
txt = CType(e.Item.Cells(1).Controls(0), TextBox)
strA = txt.Text
txt = CType(e.Item.Cells(2).Controls(0), TextBox)
strB = txt.Text
txt = CType(e.Item.Cells(3).Controls(0), TextBox)
strC = txt.Text

Dim r As myDataSet.XRow
r = myDataSet1.X.FindByRecID(key)
r.A = strA
r.B = strB
r.C = strC
OleDbDataAdapter1.Update(myDataSet1)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub
End Class

Nov 18 '05 #1
4 1462
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
OleDbDataAdapter1.Fill(myDataSet1)
DataGrid1.DataBind()
End If
End Sub

Private Sub DataGrid1_EditCommand(ByVal source As Object, ByVal e ...
DataGrid1.EditItemIndex = e.Item.ItemIndex
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_CancelCommand(ByVal source As Object, ByVal e...
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
End Sub

Private Sub DataGrid1_UpdateCommand(ByVal source As Object, ByVal e...
Dim key As String = DataGrid1.DataKeys(e.Item.ItemIndex).ToString()
Dim strA, strB, strC As String
Dim txt As TextBox
txt = CType(e.Item.Cells(1).Controls(0), TextBox)
strA = txt.Text
txt = CType(e.Item.Cells(2).Controls(0), TextBox)
strB = txt.Text
txt = CType(e.Item.Cells(3).Controls(0), TextBox)
strC = txt.Text

Dim r As myDataSet.XRow
r = myDataSet1.X.FindByRecID(key)
r.A = strA
r.B = strB
r.C = strC
OleDbDataAdapter1.Update(myDataSet1)
DataGrid1.EditItemIndex = -1
DataGrid1.DataBind()
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.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
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
9905
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...
2
3274
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...
3
4856
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...
1
4280
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...
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 =...
4
2707
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...
7
3189
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...
9
2708
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...
1
2530
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...
0
7216
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7098
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...
1
7018
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
7471
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
5028
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
4699
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
3176
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1528
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 ...
1
754
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.