Keep in mind that Web Matrix is not a separate language.  It is a
development tool.  The code below is written in VB.Net which is going to
work in Web Matrix, Visual Studio.net or Notepad.  What part do you not
understand or do you need help with?
 
The code below is written to be the code behind page or a .vb file.
 
HTH,
 
Ronda

  _____  

From: sas0riza [mailto:[EMAIL PROTECTED] 
Sent: Wednesday, September 15, 2004 8:11 AM
To: [EMAIL PROTECTED]
Subject: [AspNetAnyQuestionIsOk] How to Rewrite in Web Matrix


How do I rewrite the following in ASP.NET Web Matrix??

=====================================================================
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Web.UI.WebControls

Public Class ConfirmDelDG
  Inherits System.Web.UI.Page

  Protected WithEvents dtgProducts As 
System.Web.UI.WebControls.DataGrid
  Private strConnection As String = ConfigurationSettings.AppSettings
("NorthwindConnection")
  Private strSql As String = "SELECT ProductID, ProductName, 
UnitPrice " _
                           & "FROM Products WHERE CategoryID = 1"
  Private objConn As SqlConnection

  Private Sub Page_Load(ByVal Sender As System.Object, ByVal E As 
System.EventArgs) Handles MyBase.Load
    If Not IsPostBack Then
      BindTheGrid()
    End If
  End Sub

  Private Sub BindTheGrid()
    Connect()
    Dim adapter As New SqlDataAdapter(strSql, objConn)
    Dim ds As New DataSet()
    adapter.Fill(ds, "Products")
    Disconnect()

    dtgProducts.DataSource = ds.Tables("Products")
    dtgProducts.DataBind()
  End Sub

  Private Sub Connect()
    If objConn Is Nothing Then
      objConn = New SqlConnection(strConnection)
    End If

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

  Private Sub Disconnect()
    objConn.Dispose()
  End Sub

  Private Sub dtgProducts_ItemDataBound (ByVal sender As 
System.Object, _
    ByVal e As DataGridItemEventArgs) Handles 
dtgProducts.ItemDataBound
   
    Dim btn As Button
    If e.Item.ItemType = ListItemType.Item or e.Item.ItemType = 
ListItemType.AlternatingItem Then
      btn = CType(e.Item.Cells(0).FindControl("btnDelete"), Button)
      btn.Attributes.Add("onclick", "return confirm_delete();")
    End If

  End Sub

  Public Sub Delete_Row(ByVal Sender As Object, ByVal E As 
DataGridCommandEventArgs)

    ' Retrieve the ID of the product to be deleted
    Dim ProductID As system.Int32 = System.Convert.ToInt32
(E.Item.Cells(0).Text)

    dtgProducts.EditItemIndex = -1

    ' Create and load a DataSet
    Connect()
    Dim adapter As New SqlDataAdapter(strSql, objConn)
    Dim ds As New DataSet()
    adapter.Fill(ds, "Products")
    Disconnect()

    ' Mark the product as Deleted in the DataSet
    Dim tbl As DataTable = ds.Tables("Products")
    tbl.PrimaryKey = New DataColumn() _
                     { _
                       tbl.Columns("ProductID") _
                     }
    Dim row As DataRow = tbl.Rows.Find(ProductID)
    row.Delete()

    ' Reconnect the DataSet and delete the row from the database
    '-----------------------------------------------------------
    ' Following section commented out for demonstration purposes
    'Dim cb As New SqlCommandBuilder(adapter)
    'Connect()
    'adapter.Update(ds, "Products")
    'Disconnect()
    '-----------------------------------------------------------
    ' Display remaining rows in the DataGrid
    dtgProducts.DataSource = ds.Tables("Products")
    dtgProducts.DataBind()

  End Sub

End Class
===================================================================



Yahoo! Groups Sponsor   

ADVERTISEMENT
 
<http://us.ard.yahoo.com/SIG=129vgakdl/M=295196.4901138.6071305.3001176/D=gr
oups/S=1705006764:HM/EXP=1095340324/A=2128215/R=0/SIG=10se96mf6/*http://comp
anion.yahoo.com> click here     
 
<http://us.adserver.yahoo.com/l?M=295196.4901138.6071305.3001176/D=groups/S=
:HM/A=2128215/rand=985077063>   

  _____  

Yahoo! Groups Links


*       To visit your group on the web, go to:
http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/
  

*       To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]
e> 
  

*       Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> . 




[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Make a clean sweep of pop-up ads. Yahoo! Companion Toolbar.
Now with Pop-Up Blocker. Get it for free!
http://us.click.yahoo.com/L5YrjA/eSIIAA/yQLSAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 

Reply via email to