Question : I am trying to add an edit, delete function to an existing gridview

Here is the code. I have some declaration and coding error in the functions I am adding to the grid.
   OnRowCancelingEdit="uxItemDetailGrid_RowCancelingEdit"
   OnRowEditing="uxItemDetailGrid_RowEditing"
   OnRowUpdating="uxItemDetailGrid_RowUpdating"
   OnRowDeleting="uxItemDetailGrid_RowDeleting"

I am getting this error

Compiler Error Message: BC30002: Type 'ContactTableAdapter' is not defined.

Source Error:

 

Line 131:    Protected Sub uxItemDetailGrid_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
Line 132:
Line 133:         Dim contact As New ContactTableAdapter()
Line 134:    
Line 135:         Dim txtName As TextBox = DirectCast(uxItemDetailGrid.Rows(e.RowIndex).FindControl("strNeeds"), TextBox)
 


here is my aspx page and vb pages.
===========================================================
<%@ Page Language="VB" Debug="false" AutoEventWireup="false" CodeFile="EventRegMeals.aspx.vb" Inherits="wwwroot_EventRegMeals" %>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">





   
 






nt size="4">CMAA Northern California Dinner Meeting Meal Selection</td>
Print Instructions: Print in preview mode - Set to Landscape - Set Shrink Page to 85% - Click on Print preview.




Select Event Name:






  Select Month:

em>
Janm>
Febm>
Marm>
Aprm>
Maym>
Junm>
Julm>
Augm>
Sepm>
Octem>
Novem>
Decem>


Select Year:

em>
2009tItem>
2010tItem>
2011tItem>
2012tItem>
2013tItem>
2014tItem>
2015tItem>
2016tItem>
2017tItem>
2018tItem>
2019tItem>
2020tItem>
2021tItem>
2022tItem>
2023tItem>
2024tItem>
2025tItem>

 If you select a new event; reset the year.




   
   OnRowCancelingEdit="uxItemDetailGrid_RowCancelingEdit"
   OnRowEditing="uxItemDetailGrid_RowEditing"
   OnRowUpdating="uxItemDetailGrid_RowUpdating"
   OnRowDeleting="uxItemDetailGrid_RowDeleting"
/>
       
       
       
            "Center" HeaderText="Event
Date">
               
                                                Text='<%# Eval("dtmEvent","{0:d}") %>'>
                   

               

           

            "Left" HeaderStyle-BackColor="#A1C1D9" HeaderStyle-Font-Size="9" HeaderText="Event
Title">
               
                                                Text='<%# Eval("strTitle") %>'>
                   

               

           

            "Left" HeaderStyle-BackColor="#A1C1D9" HeaderStyle-Font-Size="9" HeaderText="Company
Name">
               
                                                Text='<%# Eval("strName") %>'>
                   

               

           

           
             "Left" HeaderStyle-BackColor="#A1C1D9" HeaderStyle-Font-Size="9" HeaderText="Meal
Selection">
                 
                     
                 


                 
                                                Text='<%# Eval("strNeeds") %>'>
                   

               

           

           

             "Center" HeaderStyle-BackColor="#A1C1D9" HeaderStyle-Font-Size="9" HeaderText="Date
Registered">
               
                                                Text='<% #Eval("dtmCreated","{0:d}") %>'>
                   

               

           

 
       

   

   



 
 

   
 
 
 


 











=============================================================================


Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Configuration
Imports System.Collections
Imports System.IO
Imports System.Text
Imports System.Xml
Imports System.Web
Imports System.Web.Security
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Web.UI.WebControls.WebParts
Imports System.Web.UI.HtmlControls

Partial Public Class wwwroot_EventRegMeals
    Inherits System.Web.UI.Page
    Private iRowsCount As Integer = 0

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load

        If Not IsPostBack Then

            Dim dtVolumeOrder As New DataTable()
            Dim strSelectCommand As String = "SELECT e.dtmEvent,e.strTitle, r.strName, r.strNeeds,r.strEmail,r.fltOrderAmount,r.blnEmailSent,r.dtmCreated FROM i2Integration_EventRegv45_Event e,i2Integration_EventRegv45_Registration r where e.intEventID = r.intEventID and r.blnEmailSent=1  Order by e.dtmEvent"
            Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
                Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
                    adapPatientBills.Fill(dtVolumeOrder)
                End Using
            End Using

            uxItemDetailGrid.DataSource = dtVolumeOrder
            uxItemDetailGrid.DataBind()

            Dim dtVolumeOrder2 As New DataTable()
            Dim strSelectCommand2 As String = "SELECT distinct(strTitle),intEventID FROM i2Integration_EventRegv45_Event order by intEventID"
            Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
                Using adapPatientBills As New SqlDataAdapter(strSelectCommand2, sqlConn)
                    adapPatientBills.Fill(dtVolumeOrder2)
                End Using
            End Using

            DroplistData.DataSource = dtVolumeOrder2
            DroplistData.DataTextField = "strTitle"
            DroplistData.DataBind()

        End If
    End Sub
    Protected Sub DroplistData_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)

        'Dim dtVolumeOrder As New DataTable()

        'Where strTitle = '" + DroplistData.SelectedValue + "'"
        'Dim strSelectCommand As String = "SELECT strTitle FROM i2Integration_EventRegv45_Event"
        'Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
        'Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
        'adapPatientBills.Fill(dtVolumeOrder)
        'End Using
        'End Using


        'DroplistData.DataSource = dtVolumeOrder
        'DroplistData.DataTextField = "strTitle"
        'DroplistData.DataBind()

        ddlYear.SelectedIndex = 0
    End Sub

    Protected Sub ddlMth_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        '+ "' AND e.strTitle = '" + DroplistData.SelectedValue
        Dim dtVolumeOrder As New DataTable()
        Dim strSelectCommand As String = "SELECT e.dtmEvent,e.strTitle,r.strName, r.strNeeds, r.dtmCreated  FROM i2Integration_EventRegv45_Event e,i2Integration_EventRegv45_Registration r where e.intEventID = r.intEventID and r.blnEmailSent=1 and (YEAR(e.dtmEvent) = '" + ddlYear.SelectedValue + "' AND MONTH(e.dtmEvent) = '" + ddlMth.SelectedValue + "' AND e.strTitle = '" + DroplistData.SelectedValue.Tostring.replace("'","''") + "') Order by e.dtmEvent"
        Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
            Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
                adapPatientBills.Fill(dtVolumeOrder)
            End Using
        End Using
        iRowsCount = dtVolumeOrder.Rows.Count - 1
        uxItemDetailGrid.DataSource = dtVolumeOrder
        uxItemDetailGrid.DataBind()

    End Sub

    Protected Sub ddlYear_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs)
        '+ "' AND e.strTitle = '" + DroplistData.SelectedValue
        Dim dtVolumeOrder As New DataTable()
        Dim strSelectCommand As String = "SELECT e.dtmEvent,e.strTitle,r.strName, r.strNeeds, r.dtmCreated FROM i2Integration_EventRegv45_Event e,i2Integration_EventRegv45_Registration r where e.intEventID = r.intEventID and r.blnEmailSent=1 and (YEAR(e.dtmEvent) = '" + ddlYear.SelectedValue + "' AND MONTH(e.dtmEvent) = '" + ddlMth.SelectedValue + "' AND e.strTitle = '" + DroplistData.SelectedValue.Tostring.replace("'","''") + "') Order by e.dtmEvent"
        Using sqlConn As New SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
            Using adapPatientBills As New SqlDataAdapter(strSelectCommand, sqlConn)
                adapPatientBills.Fill(dtVolumeOrder)
            End Using
        End Using
        iRowsCount = dtVolumeOrder.Rows.Count - 1
        uxItemDetailGrid.DataSource = dtVolumeOrder
        uxItemDetailGrid.DataBind()
    End Sub

    Public Overloads Overrides Sub VerifyRenderingInServerForm(ByVal control As Control)
        ' Verifies that the control is rendered
    End Sub

    Protected Sub OnPaging(ByVal sender As Object, ByVal e As GridViewPageEventArgs)
        uxItemDetailGrid.PageIndex = e.NewPageIndex
        uxItemDetailGrid.DataBind()
    End Sub


    Protected Sub btnReturn_Click(ByVal sender As Object, ByVal e As EventArgs)
        'Dim URL = "http://www.cmaanorcalevents.com/"
        Response.Redirect("http://www.cmaanorcalevents.com") ' return to clients website
    End Sub

    Protected Sub btnExportExcel_Click(ByVal sender As Object, ByVal e As EventArgs)
        Response.Clear()
        Response.Buffer = True
        'For Word:
        'Response.AddHeader("content-disposition", "attachment;filename=data.doc")
        'Response.ContentType = "application/vnd.ms-word"
        'For Excel
        Response.AddHeader("content-disposition", "attachment;filename=Mealdata.xls")
        Response.ContentType = "application/vnd.ms-excel"
        Response.Charset = ""
        Me.EnableViewState = False
        Dim oStringWriter As New System.IO.StringWriter()
        Dim oHtmlTextWriter As New System.Web.UI.HtmlTextWriter(oStringWriter)
        uxItemDetailGrid.RenderControl(oHtmlTextWriter)
        Response.Write(oStringWriter.ToString())
        Response.[End]()
    End Sub

    Protected Sub uxItemDetailGrid_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)

         Dim contact As New ContactTableAdapter()
   
         Dim txtName As TextBox = DirectCast(uxItemDetailGrid.Rows(e.RowIndex).FindControl("strNeeds"), TextBox)

         contact.Update(txtName.Text)
         uxItemDetailGrid.EditIndex = -1
       
         FillGrid()
     End Sub

Protected Sub uxItemDetailGrid_RowEditing(ByVal sender As Object, ByVal e As GridViewEditEventArgs)
    uxItemDetailGrid.EditIndex = e.NewEditIndex
    FillGrid()
End Sub

Protected Sub uxItemDetailGrid_RowCancelingEdit(ByVal sender As Object, ByVal e As GridViewCancelEditEventArgs)
    uxItemDetailGrid.EditIndex = -1
    FillGrid()
End Sub

Protected Sub uxItemDetailGrid_RowDeleting(ByVal sender As Object, ByVal e As GridViewDeleteEventArgs)
    Dim contact As New ContactTableAdapter()
    Dim id As Integer = Convert.ToInt32(uxItemDetailGrid.DataKeys(e.RowIndex).Values(0).ToString())
    contact.Delete(id)
    FillGrid()
End Sub

End Class

Answer : I am trying to add an edit, delete function to an existing gridview

you have " .." in SqlConnection constructor...should be like below:
conn = new SqlConnection(ConfigurationManager.ConnectionStrings("SiteSqlServer").ConnectionString)
Random Solutions  
 
programming4us programming4us