Datagrid button column gives BC30456: "not a member" error

Discussion in 'ASP .Net Datagrid Control' started by Tom, Jun 26, 2004.

  1. Tom

    Tom Guest

    Hi,

    Relatively new to asp.net and having some trouble wiring up a button
    column in a datagrid. I keep getting the error: BC30456: 'AddToCart'
    is not a member of 'ASP.homepage_aspx'.
    Have been following the guidelines in ASP.NET Data Web Controls, but
    seem to be pounding my head on the wall.

    Probably an easy fix for one of you all. Would really appreciate your
    input. Thanks in advance.

    Tom

    Here's the code:

    <body MS_POSITIONING="GridLayout">
    <form id="homepage" action="browse_cat.aspx" method="post"
    runat="server">
    <asp:label id="lblCategory" style="Z-INDEX: 101; LEFT:
    251px; POSITION: absolute; TOP: 10px" runat="server" Width="59px"
    Height="30px">Category</asp:label>
    <asp:dropdownlist id="ddlCategories" style="Z-INDEX: 102;
    LEFT: 327px; POSITION: absolute; TOP: 10px" runat="server"
    Width="218px" Height="31px" AutoPostBack="True"></asp:dropdownlist>
    <asp:datagrid id="grdProducts" style="Z-INDEX: 103; LEFT:
    44px; POSITION: absolute; TOP: 47px" runat="server" Width="575px"
    Height="148px" OnItemCommand="AddToCart" AutoGenerateColumns="False"
    AllowPaging="True">
    <Columns>
    <asp:BoundColumn DataField="product_num"
    HeaderText="Product #"></asp:BoundColumn>
    <asp:BoundColumn DataField="description"
    HeaderText="Description"></asp:BoundColumn>
    <asp:BoundColumn DataField="price"
    HeaderText="Price"></asp:BoundColumn>
    <asp:BoundColumn DataField="qty_on_hand"
    HeaderText="Qty On-Hand"></asp:BoundColumn>
    <asp:TemplateColumn HeaderText="Qty">
    <EditItemTemplate>
    <asp:TextBox id=txtAddToCart
    runat="server" Text='<%# DataBinder.Eval(DsCart1,
    "Tables[Cart].DefaultView.[0].cart_qty_ord") %>'>
    </asp:TextBox>
    </EditItemTemplate>
    </asp:TemplateColumn>
    <asp:ButtonColumn Text="Add"
    ButtonType="PushButton" HeaderText="Add to Cart"
    CommandName="Add2Cart"></asp:ButtonColumn>
    </Columns>
    </asp:datagrid></form>
    </body>
    </HTML>

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


    Public Class WebForm1
    Inherits System.Web.UI.Page
    Protected WithEvents DsCategory1 As test3.dsCategory
    Protected WithEvents lblCategory As
    System.Web.UI.WebControls.Label
    Protected WithEvents ddlCategories As
    System.Web.UI.WebControls.DropDownList

    Protected WithEvents grdProducts As
    System.Web.UI.WebControls.DataGrid


    #Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.
    <System.Diagnostics.DebuggerStepThrough()> Private Sub
    InitializeComponent()

    End Sub

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Init
    'CODEGEN: This method call is required by the Web Form
    Designer
    'Do not modify it using the code editor.
    InitializeComponent()
    End Sub

    #End Region

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    System.EventArgs) Handles MyBase.Load
    'Put user code to initialize the page here
    If Not Page.IsPostBack Then
    CategoryLoad()
    End If

    End Sub

    Private Sub CategoryLoad()
    'create a connection
    Const strCatLoadConn As String =
    "server=localhost;uid=sa;pwd=;database=tsproductsSQL3"

    ' data source=ENVISAGENT1;initial
    catalog=tsproductsSQL3;integrated security=SSPI;persist security
    info=False;workstation id=ENVISAGENT1;packet size=4096
    Dim objCatLoadConn As New SqlConnection(strCatLoadConn)


    'create command object for query
    Dim strSQLCatLoad As String = "select category_num,
    category_description " & _
    "from category_detail"


    objCatLoadConn.Open() 'open connection

    'specify data adapter and data source and call databind
    Dim da2 As SqlDataAdapter
    Dim ds2 As DataSet

    ds2 = New DataSet()
    da2 = New SqlDataAdapter(strSQLCatLoad, strCatLoadConn)
    da2.Fill(ds2)

    With ddlCategories
    .DataTextField = "category_description"
    .DataValueField = "category_num"
    .DataSource = ds2
    .DataBind()
    End With
    objCatLoadConn.Close() 'close connection

    End Sub

    Private Sub ddlCategories_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    ddlCategories.SelectedIndexChanged
    ProductsLoad()
    End Sub

    Private Sub ProductsLoad()
    'create a connection
    Const strProdLoadConn As String =
    "server=localhost;uid=sa;pwd=;database=tsproductsSQL3"
    Dim objProdLoadConn As New SqlConnection(strProdLoadConn)
    Dim dsProdLoad As DataSet
    Dim daProdLoad As SqlDataAdapter

    dsProdLoad = New DataSet()

    'create command object for query
    Dim strSQLProdLoad As String =
    daProdLoad.SelectCommand.CommandText & _
    " Where category_num = " & _
    ddlCategories.SelectedItem.Value

    objProdLoadConn.Open() 'open connection

    'specify data adapter and data source and call databind
    daProdLoad = New SqlDataAdapter(strSQLProdLoad,
    strProdLoadConn)
    daProdLoad.Fill(dsProdLoad)

    With grdProducts
    .DataSource = dsProdLoad
    .DataBind()
    End With
    objprodLoadConn.Close() 'close connection
    End Sub

    Sub AddToCart(ByVal sender As Object, ByVal e As
    DataGridCommandEventArgs)
    'Take item selected and put it into shopping cart
    Dim ProdNumCol As TableCell = e.Item.Cells(0)
    Dim DescCol As TableCell = e.Item.Cells(1)
    Dim PriceCol As TableCell = e.Item.Cells(2)
    Dim Qoh As TableCell = e.Item.Cells(3)
    Dim Qty As TableCell = e.Item.Cells(4)
    Dim AddTo As TableCell = e.Item.Cells(5)

    End Sub





    Private Sub grdProducts_SelectedIndexChanged(ByVal sender As
    System.Object, ByVal e As System.EventArgs) Handles
    grdProducts.SelectedIndexChanged

    End Sub
    End Class
     
    Tom, Jun 26, 2004
    #1
    1. Advertising

  2. Hi Tom,

    I don't see where you are capturing the ItemCommand event. If you add this
    to your code does it help?

    Private Sub grdProducts_ItemCommand _
    (ByVal source As Object, _
    ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) _
    Handles grdProducts.ItemCommand
    Call AddToCart(source, e)
    End Sub

    Ken
    Microsoft MVP [ASP.NET]


    "Tom" <> wrote in message
    news:...
    > Hi,
    >
    > Relatively new to asp.net and having some trouble wiring up a button
    > column in a datagrid. I keep getting the error: BC30456: 'AddToCart'
    > is not a member of 'ASP.homepage_aspx'.
    > Have been following the guidelines in ASP.NET Data Web Controls, but
    > seem to be pounding my head on the wall.
    >
    > Probably an easy fix for one of you all. Would really appreciate your
    > input. Thanks in advance.
    >
    > Tom
    >
    > Here's the code:
    >
    > <body MS_POSITIONING="GridLayout">
    > <form id="homepage" action="browse_cat.aspx" method="post"
    > runat="server">
    > <asp:label id="lblCategory" style="Z-INDEX: 101; LEFT:
    > 251px; POSITION: absolute; TOP: 10px" runat="server" Width="59px"
    > Height="30px">Category</asp:label>
    > <asp:dropdownlist id="ddlCategories" style="Z-INDEX: 102;
    > LEFT: 327px; POSITION: absolute; TOP: 10px" runat="server"
    > Width="218px" Height="31px" AutoPostBack="True"></asp:dropdownlist>
    > <asp:datagrid id="grdProducts" style="Z-INDEX: 103; LEFT:
    > 44px; POSITION: absolute; TOP: 47px" runat="server" Width="575px"
    > Height="148px" OnItemCommand="AddToCart" AutoGenerateColumns="False"
    > AllowPaging="True">
    > <Columns>
    > <asp:BoundColumn DataField="product_num"
    > HeaderText="Product #"></asp:BoundColumn>
    > <asp:BoundColumn DataField="description"
    > HeaderText="Description"></asp:BoundColumn>
    > <asp:BoundColumn DataField="price"
    > HeaderText="Price"></asp:BoundColumn>
    > <asp:BoundColumn DataField="qty_on_hand"
    > HeaderText="Qty On-Hand"></asp:BoundColumn>
    > <asp:TemplateColumn HeaderText="Qty">
    > <EditItemTemplate>
    > <asp:TextBox id=txtAddToCart
    > runat="server" Text='<%# DataBinder.Eval(DsCart1,
    > "Tables[Cart].DefaultView.[0].cart_qty_ord") %>'>
    > </asp:TextBox>
    > </EditItemTemplate>
    > </asp:TemplateColumn>
    > <asp:ButtonColumn Text="Add"
    > ButtonType="PushButton" HeaderText="Add to Cart"
    > CommandName="Add2Cart"></asp:ButtonColumn>
    > </Columns>
    > </asp:datagrid></form>
    > </body>
    > </HTML>
    >
    > Imports System.Data
    > Imports System.Data.SqlClient
    > Imports System.Web.UI.WebControls
    >
    >
    > Public Class WebForm1
    > Inherits System.Web.UI.Page
    > Protected WithEvents DsCategory1 As test3.dsCategory
    > Protected WithEvents lblCategory As
    > System.Web.UI.WebControls.Label
    > Protected WithEvents ddlCategories As
    > System.Web.UI.WebControls.DropDownList
    >
    > Protected WithEvents grdProducts As
    > System.Web.UI.WebControls.DataGrid
    >
    >
    > #Region " Web Form Designer Generated Code "
    >
    > 'This call is required by the Web Form Designer.
    > <System.Diagnostics.DebuggerStepThrough()> Private Sub
    > InitializeComponent()
    >
    > End Sub
    >
    > Private Sub Page_Init(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Init
    > 'CODEGEN: This method call is required by the Web Form
    > Designer
    > 'Do not modify it using the code editor.
    > InitializeComponent()
    > End Sub
    >
    > #End Region
    >
    > Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
    > System.EventArgs) Handles MyBase.Load
    > 'Put user code to initialize the page here
    > If Not Page.IsPostBack Then
    > CategoryLoad()
    > End If
    >
    > End Sub
    >
    > Private Sub CategoryLoad()
    > 'create a connection
    > Const strCatLoadConn As String =
    > "server=localhost;uid=sa;pwd=;database=tsproductsSQL3"
    >
    > ' data source=ENVISAGENT1;initial
    > catalog=tsproductsSQL3;integrated security=SSPI;persist security
    > info=False;workstation id=ENVISAGENT1;packet size=4096
    > Dim objCatLoadConn As New SqlConnection(strCatLoadConn)
    >
    >
    > 'create command object for query
    > Dim strSQLCatLoad As String = "select category_num,
    > category_description " & _
    > "from category_detail"
    >
    >
    > objCatLoadConn.Open() 'open connection
    >
    > 'specify data adapter and data source and call databind
    > Dim da2 As SqlDataAdapter
    > Dim ds2 As DataSet
    >
    > ds2 = New DataSet()
    > da2 = New SqlDataAdapter(strSQLCatLoad, strCatLoadConn)
    > da2.Fill(ds2)
    >
    > With ddlCategories
    > .DataTextField = "category_description"
    > .DataValueField = "category_num"
    > .DataSource = ds2
    > .DataBind()
    > End With
    > objCatLoadConn.Close() 'close connection
    >
    > End Sub
    >
    > Private Sub ddlCategories_SelectedIndexChanged(ByVal sender As
    > System.Object, ByVal e As System.EventArgs) Handles
    > ddlCategories.SelectedIndexChanged
    > ProductsLoad()
    > End Sub
    >
    > Private Sub ProductsLoad()
    > 'create a connection
    > Const strProdLoadConn As String =
    > "server=localhost;uid=sa;pwd=;database=tsproductsSQL3"
    > Dim objProdLoadConn As New SqlConnection(strProdLoadConn)
    > Dim dsProdLoad As DataSet
    > Dim daProdLoad As SqlDataAdapter
    >
    > dsProdLoad = New DataSet()
    >
    > 'create command object for query
    > Dim strSQLProdLoad As String =
    > daProdLoad.SelectCommand.CommandText & _
    > " Where category_num = " & _
    > ddlCategories.SelectedItem.Value
    >
    > objProdLoadConn.Open() 'open connection
    >
    > 'specify data adapter and data source and call databind
    > daProdLoad = New SqlDataAdapter(strSQLProdLoad,
    > strProdLoadConn)
    > daProdLoad.Fill(dsProdLoad)
    >
    > With grdProducts
    > .DataSource = dsProdLoad
    > .DataBind()
    > End With
    > objprodLoadConn.Close() 'close connection
    > End Sub
    >
    > Sub AddToCart(ByVal sender As Object, ByVal e As
    > DataGridCommandEventArgs)
    > 'Take item selected and put it into shopping cart
    > Dim ProdNumCol As TableCell = e.Item.Cells(0)
    > Dim DescCol As TableCell = e.Item.Cells(1)
    > Dim PriceCol As TableCell = e.Item.Cells(2)
    > Dim Qoh As TableCell = e.Item.Cells(3)
    > Dim Qty As TableCell = e.Item.Cells(4)
    > Dim AddTo As TableCell = e.Item.Cells(5)
    >
    > End Sub
    >
    >
    >
    >
    >
    > Private Sub grdProducts_SelectedIndexChanged(ByVal sender As
    > System.Object, ByVal e As System.EventArgs) Handles
    > grdProducts.SelectedIndexChanged
    >
    > End Sub
    > End Class
     
    Ken Cox [Microsoft MVP], Jun 28, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. TN Bella
    Replies:
    2
    Views:
    2,312
    TN Bella
    Jun 20, 2004
  2. Zenobia
    Replies:
    1
    Views:
    7,302
    Zenobia
    Jul 6, 2004
  3. =?Utf-8?B?Y2RiaWdncw==?=

    What is 'Error BC30456? (Not a member of ASP.Default_aspx?)

    =?Utf-8?B?Y2RiaWdncw==?=, Jun 21, 2006, in forum: ASP .Net
    Replies:
    0
    Views:
    819
    =?Utf-8?B?Y2RiaWdncw==?=
    Jun 21, 2006
  4. Tony Girgenti
    Replies:
    7
    Views:
    2,594
    Ken Cox [Microsoft MVP]
    Oct 5, 2006
  5. Tony Girgenti
    Replies:
    7
    Views:
    256
    Ken Cox [Microsoft MVP]
    Oct 5, 2006
Loading...

Share This Page