Has anyone downloaded .NET 2.0 Beta?

I downloaded .NET 2.0 beta and found that code using dataset insert new row at top of datagrids is broken.

Any suggestions to fix it?
The code(that works fine with Net 1.1) is at:
http://www.learnasp.com/freebook/learn/xmlbooksedit.aspx
or below
<%@ Page Language="vb" %>
<%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>
<%@ import Namespace="System.Drawing" %>
<script runat="server">
Private strConnection As String = "server=localhost;uid=sa;pwd=password;database=Northwind"
Private strSQLSelect As String = "SELECT * from Products"
Private ProductTableName As String = "Products"
Private objConnection As SqlConnection
' Important: Table must have a PRIMARY KEY. In this instance, it is PRODUCTID
' Cells are coded with column position in the datagrid counting from 0.
' ========================================

Private Sub Page_Load(ByVal Sender As Object, ByVal E As EventArgs)
If Not IsPostBack Then
LoadGrid()
End If
End Sub
' ========================================

Private Sub LoadGrid()
Connect()

'
Dim sql as string
If viewstate("sortfield") Is Nothing Then
sql = strSQLSelect
Else
sql = strSQLSelect & " order by " & viewstate("sortfield") & " " & viewstate("sortdirection")
End If

Dim adapter As New SqlDataAdapter(sql, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, ProductTableName)
Disconnect()

'ok let's get fancy and insert a blank row at the top
dim sw1 as integer = 1
select case sw1
case 1
dim dr as datarow = ds.Tables(0).newrow()
'put something in the first primary key CustomerID
'dr("Productname") = " (Add new Product name here)"
ds.Tables(0).rows.insertat(dr, 0)

end select
dgProducts.DataSource = ds.Tables(ProductTableName)
dgProducts.DataBind()
End Sub
' ========================================
Private Sub Connect()
If objConnection Is Nothing Then
objConnection = New SqlConnection(strConnection)
End If

If objConnection.State = ConnectionState.Closed Then
objConnection.Open()
End If
End Sub

Private Sub Disconnect()
objConnection.Close()
End Sub
' ========================================

Public Sub EditRecord(ByVal Sender As Object, _
ByVal E As DataGridCommandEventArgs)
dgProducts.EditItemIndex = E.Item.ItemIndex
LoadGrid()
End Sub


' ========================================
Public Sub CancelEdit(ByVal Sender As Object, _
ByVal E As DataGridCommandEventArgs)
dgProducts.EditItemIndex = -1
LoadGrid()
End Sub

' ========================================
Public Sub UpdateRecord(ByVal Sender As Object, _
ByVal E As DataGridCommandEventArgs)

Dim NameTextBox As TextBox = CType(E.Item.Cells(1).Controls(0), TextBox)
Dim Name As string = Convert.tostring(NameTextBox.Text)
Dim PriceTextBox As TextBox = CType(E.Item.Cells(2).Controls(0), TextBox)
Dim Price As string = Convert.tostring(PriceTextBox.Text)

' Create and load a DataSet with records from Northwind.Products table
Connect()
Dim adapter As New SqlDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, ProductTableName)
Disconnect()

dim row as datarow
Dim currentRow As Integer = e.Item.DataSetIndex

'ADD NEW
if currentrow = 0 then

row = ds.tables(0).newrow()
row.Item("ProductName") = Name
row.item("Unitprice")= Price
ds.tables(0).rows.insertat(row, 0 )

else
'UPDATING EXISTING RECORD
' Retrieve the field values in the edited row
Dim ProductID As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)

' Modify the in-memory records in the DataSet
Dim tbl As DataTable = ds.Tables(ProductTableName)
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("ProductID") _
}
row = tbl.Rows.Find(ProductID)
row.Item("ProductName") = Name
row.item("Unitprice")= Price

End if

' Reconnect the DataSet and update the database
Dim cb As New SqlCommandBuilder(adapter)
Connect()
adapter.Update(ds, ProductTableName)
Disconnect()

dgProducts.DataSource = ds.Tables(ProductTableName)
dgProducts.DataBind()
dgProducts.EditItemIndex = -1
Loadgrid()
End Sub


' ========================================

Sub DeleteRecord(Sender As Object, E As DataGridCommandEventArgs)

' Retrieve the field values in the edited row
Dim ProductID As Int32 = Convert.ToInt32(E.Item.Cells(0).Text)

' Create and load a DataSet with records from Northwind.Products table
Connect()
Dim adapter As New SqlDataAdapter(strSQLSelect, objConnection)
Dim ds As New DataSet()
adapter.Fill(ds, ProductTableName)
Disconnect()

' Modify the in-memory records in the DataSet
Dim tbl As DataTable = ds.Tables(ProductTableName)
tbl.PrimaryKey = New DataColumn() _
{ _
tbl.Columns("ProductID") _
}
Dim row As DataRow = tbl.Rows.Find(ProductID)
row.Delete()


' Reconnect the DataSet and update the database
Dim cb As New SqlCommandBuilder(adapter)
Connect()
adapter.Update(ds, ProductTableName)
Disconnect()

dgProducts.DataSource = ds.Tables(ProductTableName)
dgProducts.DataBind()
dgProducts.EditItemIndex = -1
Loadgrid()
End Sub


' ===================================
public sub dg_itemcreated ( sender as object, e as datagriditemeventargs )
'
' Clear column headers for col 3 and col 4 col3 + edit col 4 = delete
If e.Item.ItemType = ListItemType.Header Then
e.Item.Cells(3).Backcolor = Color.White
e.Item.Cells(4).Backcolor = Color.White
end If

'-- add logic to modify text literal EDIT and Suppress the Delete

if e.item.itemindex = 0 then 'first row
'reference the AddNEW row
e.Item.BackColor = Color.gold
e.Item.Cells(4).Backcolor = Color.White
dim lbDelete as linkbutton = e.item.cells(4).controls(0)
dim lbEdit as linkbutton = e.item.cells(3).controls(0)

if lbDelete.text = "Delete" then
lbDelete.text = ""
end if
if lbEdit.text = "Edit" then
lbEdit.text = "Add New"
end if
if lbEdit.text = "Save" then
lbEdit.text = "Save"
end if
end if

if e.item.itemindex > 0 then


dim mydeletebutton as tablecell
mydeletebutton = e.item.cells(4)
mydeletebutton.attributes.add("onclick", _
"return confirm('Are you sure you want to delete this record?');" )

end if
end sub

' ========================================

Sub DataSort(Src As Object, E As DataGridSortCommandEventArgs)
viewstate.Add("sortfield", e.SortExpression)
If viewstate("sortdirection") Is Nothing Then
viewstate.Add("sortdirection", "ASC")
Else
If viewstate("sortdirection") = "ASC" Then
viewstate("sortdirection") = "DESC"
Else
viewstate("sortdirection") = "ASC"
End If
End If
LoadGrid()
End Sub
</script>
<html>
<head>
<title>Sample add/edit/delete datagrid SQL Server</title>
</head>
<body>
<form id="Form1" method="post" runat="server">
<br />
<div style="VERTICAL-ALIGN: top; OVERFLOW: auto; POSITION: relative; HEIGHT: 300px" align="left" width="70%">
<asp:datagrid id="dgProducts" runat="server" width="100%" OnSortCommand="Datasort" AllowSorting="True" CellPadding="5" AutoGenerateColumns="false" OnEditCommand="EditRecord" OnCancelCommand="CancelEdit" OnUpdateCommand="Updaterecord" DataKeyField="ProductID" ondeletecommand="DeleteRecord" onitemcreated="dg_itemcreated">
<HeaderStyle backcolor="Silver"></HeaderStyle>
<Columns>
<asp:BoundColumn ItemStyle-Width="100px" visible="false" DataField="productid" SortExpression="ProductID" ReadOnly="True"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-Width="400px" DataField="ProductName" HeaderText="Name" SortExpression="ProductName"></asp:BoundColumn>
<asp:BoundColumn ItemStyle-Width="100px" DataField="unitprice" DataFormatString="{0:c}" SortExpression="UnitPrice" HeaderText="Price"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Save" CancelText="Cancel" EditText="Edit"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Delete" CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid>
</div>
</form>
</body>
</html>
0
coriolan
10/11/2004 9:42:25 PM
asp.net.presentation-controls 72751 articles. 3 followers. Follow

0 Replies
204 Views

Similar Articles

[PageSpeed] 47

Reply:

Similar Artilces:

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0 #2
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! There are too many differences for one email - - from 1.0 to 1.1 (not a whole lot of real change, other than fixes, at least compared to 1.1 to 2.0) With 2.0, there were many new declarative controls, with many new ideas added in With 3.0, it's a superset of 2.0 - instead of replacing the installation completely, it just 'added on' new functionality - I would...

Clickonce deployment anyone (DW.NET 2.0 and .NET 2.0)?
I saw someone had posted a question about this already, and there were no responses. So I am hoping that this will get some. We had problems with the previous version of DW.NET 1.5 + VS2003 when attempting to deploy applications via a web server. So many problems that we eventually decided to run off a network drive (which is OK if your user base doesn't roam around the country). Anyway, we gave up on DW.NET, and started to use the datagrid control. Since then, much has changed. Our development team now has VS2005 professional and may start using DW.NET 2.0 (pending my inv...

.NET 2.0 Data Connection (.NET 2.0 Beta Data Provider)
I have installed the .NET 2.0 Beta Data Provider, in the server explorer in Visual Studio 2005 I have tried to connect to this provider but I can not see it in the list. Is there something else you need to do to see this other than what is in the instructions or is this not supported yet? Hi Dean, I assume you mean ASE ADO.NET 2.0 Beta. I'm attaching the html readme for this product that you should have from downloading it. Are you talking about using Server Explorer to see the Provider? This functionality isn't working yet and should be available on GA or shortly ...

web.config problems when upgrading from .NET 2.0 Beta to .NET 2.0 release version
We uninstalled .NET 2.0 Beta and replaced it with .NET 2.0 release version.  And it messed everything up.  All applications now give weird errors indicating the lack of web.config files, despite the fact that they already have web.config files in place.  For example, the following error occurs even though the web.config file has <customErrors="Off">: Runtime Error Description: An application error occurred on the server. The current custom error settings for this application prevent the details of the application error from being viewed remotely (for securit...

Differences between .net 1, .net 1.1, .net 2.0 and .net 3.0
Hi, This seems to be a common question, but i havent got an answer yet:(Can, any one please explain me the differences between these versions.If you keep your feet firmly on the ground, you'll have trouble putting on your pants! Have a look into this links http://en.wikipedia.org/wiki/.NET_Framework http://blogs.msdn.com/mohammadakif/archive/2006/12/03/net-3-0-different-versions-of-the-net-framework.aspx http://www.codeproject.com/aspnet/ComparisonASP1xASP20.aspAshok Rajawww.iGold.inDon't forget to click "Mark as Answer" on the post that helped you. This credits that m...

.NET v1.1 SP1 and .NET 2.0 beta 2
Hi all I want to install VWD and .NET 2.0 beta 2 on the same machine that I am using Delphi.NET and .NET v1.1 SP1. I am considering jumping from Delphi to C# and this is an ideal way to do it. I do however have too many web applications on the v1.1 framework that are published on servers that do not support 2.0 as yet. Can these 2 versions of the framework co-exist so I can carry on in Delphi with existing sites but start new ones in VWD? I did take the chance on one of my machines and both VWD and Delphi seem to compile their respective web apps okay. I have not tested deplo...

.Net 2.0 Web application using Vb.net is unable to create object of another dll writen in C# .net 2.0
Hi, I habe created one ASP.net web application using Vb.net which is adding reference of dlls written in C# and .net 2.0. But whenever trying to create object of referencing dll, it is throwing error :Object reference does not set to an object. But, locally it is working fine,. In the server i have deployed the .aspx files and dll files in the bin. There were already an web.config in the server which is of .net 1.1. But checked it is retrieving value for that web.config correctly. Should i have to deply any other files and if not what can be the solution for this? Please help. Thanks, So...

Unable to access page controls from base class in .NET 2.0 Beta 2
Hello All, I have converted a large-ish project to VS2005 beta 2. It is going better than beta 1, but it's still a world of pain. The latest problem is that I can't seem to access page controls from within a base class. I'm sure I didn't get this on beta 1 so maybe something has changed. Or maybe I'm just tired and it'll seem obvious tomorrow (it's the end of the working day here in the UK). Anyway, my problem: I have a page, Administration.aspx, a code behind file Administration.aspx.cs (with an Administration class), and, in a seperate project, a class called AdminPage. ...

Access .Net 2.0 Application from .Net 2.0 Web Site
I need to populate a specific form in a .Net desktop application from a .net web application.  Is there an easy way to go about this? Hi, Based on my understanding, you want to start an executable application from your ASP.NET websit, right? We can invoke Process.Start method (http://msdn.microsoft.com/en-us/library/system.diagnostics.process.start.aspx) to launch an executable application from ASP.NET application. Note: Please keep in mind, the ASP.NET application is running on the server, so it will start the executable application that exists in the server.   I look...

.NET 3.0 or .NET 2.0?
I'm going to move my exiting software to .net soon. I'm just wondering if I should wait for the .NET 3.0 framework to be released or if I can start with the 2.0 now? I'd say you can go ahead and move your code to .Net 2.0 as .Net 3.0 uses the CLR version 2.0.Basically, .net 3.0 is .net 2.0 PLUS some new features for presentation (GUI), communication and workflow process.  So the compiler as well as the language features used by the 2.0 runtime will be the same in 2.0 and 3.0"Never argue with an idiot; He will drag you down to his level and beat you with experienc...

Download SpreadsheetGear for .NET 1.0.2 Beta 2, a Royalty Free Microsoft Excel Compatible Spreadsheet Component
SpreadsheetGear for .NET SpreadsheetGear for .NET is a royalty free Microsoft Excel compatible spreadsheet component built by industry veterans for the Microsoft .NET Framework. SpreadsheetGear for .NET provides .NET Framework developers the tool they need to leverage the existing skills of Excel users by allowing these users to design reports, specify business rules, set up complex calculations and provide tables of data in a form in which they are both knowledgeable and comfortable. SpreadsheetGear for .NET features the fastest spreadsheet calculation engine available. All of E...

Downloads are for .net 3.5 but all the starter kits are .net 2.0!?!?
I assume I'm missing something, but after downloading the installer for the latest products - web developer, etc, I downloaded some starter kits, dotnetnuke, the soccer club deal, and a couple others. Of course, none of them would compile and some use solutions, which apparently, express doesn't handle. Why are the starter kits here, as resources, if they aren't compatible with the products available on this site? If I'm suppposed to use an older version of studio express, which one and where do I get it?  I think the run time of 3.5 is same as 2.0, because 3.5 buid on...

.Net 2.0 Beta 2
Dear All,I used to have .NET 1.1 and .NET 2.0 Beta 1 installed on the same machine, at that time, in the IIS management console, I can pick an website to run on either .NET 1.1 or .NET 2.0, but I found out I do not have this option after I installed .NET 2.0 Beta 2, is it because of .NET 2.0 Beta 2 cannot run on IIS 5.1? Any clue will be greatly appreciated!ChinThank you try this Go to command prompt and change to this directory c:\windows\microsoft.net\framework\v2.0????? Once in this directory run this aspnet_regiis -Ithere are a few post with more details, but try that first. Tha...

Running server controls compiled for .NET 1.1 in .NET 2.0
Hello, I have tried upgrading our ASP.NET 1.1 application to .NET 2.0 by using Web Application Projects, and it works beautifully. We use several 3rd party controls that we bought for use in .NET 1.1 and these seem to just work in .NET 2.0, except that I get an intermittent problem with one of them. Should DLLs compiled using .NET 1.1 simply work, except if they access classes that have been removed from the framework in .NET 2.0? If I have both .NET 1.1 and .NET 2.0 present on the machine and the ASP.NET application is configured to run using .NET 2.0 and I have a DLL compiled using .NE...

Web resources about - Has anyone downloaded .NET 2.0 Beta? - asp.net.presentation-controls

Downloaded (film) - Wikipedia, the free encyclopedia
It follows Napster from its rise in 1998, through the swarm of lawsuits that ensued and to its acquisition by Rhapsody in 2011. Some of those ...

Can I still use the Rooms app if I’ve already downloaded it? - Rooms für iPhone
Rooms will be closing its doors on December 23, 2015. After then the app will switch to read-only mode and you’ll no longer be able to post. ...

All sizes - (1) Shazam'd an REM song, (2) downloaded their best of, (3) listened it - Flickr - Photo ...
Flickr is almost certainly the best online photo management and sharing application in the world. Show off your favorite photos and videos to ...

Downloaded - Trailer - YouTube
http://www.trailerobsessed.com A VH1 Documentary about the Downloading generation, and the global impact of peer-to-peer filesharing. The bands, ...

Google Maps for iPhone downloaded by 10m
Google Maps became the top free app in the Apple App Store just a few hours after it was released late on Thursday. Now, we know just how popular ...

HBO tracking down pirates who downloaded leaked Game of Thrones episodes
HBO sends out a flurry of take-downs and infringement notices after millions download leaked Game of Thrones episodes.

100 Bloody Acres one of the most illegally downloaded films
Nearly 2000 downloads per day turn Cairnes brothers' horror-comedy hit into piracy gold.

Downloaded Q&A w/ Janet Pierson, Alex Winters (Dir.) Sean Parker and Shawn Fanning (Napster) - YouTube ...
Q&A w/ Janet Pierson (SXSW), Alex Winters (Dir.) Sean Parker and Shawn Fanning after a screening of DOWNLOADED, a documentary about the creation ...

Xbox One to allow loaning, trading of downloaded games
Microsoft senior director Albert Penello says "that has to be part of the experience" eventually, along with subsidized console promotions

800K TV episodes and 350K movies downloaded per day on iTunes
... and WatchESPN have joined Apple TV. Plus, HBO GO and WatchESPN have joined Apple TV. Apple has this week revealed that iTunes users have downloaded ...

Resources last updated: 12/14/2015 10:53:50 AM