Wrox Programmer Forums
|
BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003
This is the forum to discuss the Wrox book Professional VB.NET 2003 by Bill Evjen, Billy Hollis, Rockford Lhotka, Tim McCarthy, Jonathan Pinnock, Rama Ramachandran, Bill Sheldon; ISBN: 9780764559921
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 15th, 2004, 05:56 PM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default Another Chapter 17 problem (DataGrid Update)

Hi.

I get an exception, and can't figure it out.
Can someone please help me?

BC30456: DataItem is not a member of System.Web.UI.Control.

Line 91: <ASP:TEMPLATECOLUMN itemstyle-wrap="False" headertext="Spille tid" datafield="Spilletid">
Line 92: <ITEMTEMPLATE>
Line 93: <ASP:LABEL id=Spilletid runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Spilletid", "{0:c}") %>'>
Line 94: </ASP:LABEL>
Line 95: </ITEMTEMPLATE>




*****************************************
Code (I'm using OleDB, and a private database):
<%@ import Namespace="System.Data.SQLClient" %>
<%@ import Namespace="System.Data.OleDB" %>
<%@ import Namespace="System.Data" %>
<HTML>
    <HEAD>
        <TITLE>updateGrid</TITLE>
        <META content="Internet Explorer 6.0" name="vs_targetSchema">
        <SCRIPT language="vb" runat="server">
' Dim objConnection As SqlConnection
        Dim strConnection AS String = "Provider=MSDAORA.1;Password=abc;User ID=abc;Data Source=ABCSOURCE"
        Dim objConnection as New OleDbConnection(strConnection)

        Sub Page_Load(Sender as Object, E As EventArgs)
            If Not (IsPostBack)
                BindGrid()
            End If
        End Sub

        Sub Page_Unload(Sender as Object, E as EventArgs)
            objConnection = Nothing
        End Sub

        Sub BindGrid()
            Dim objDataSet as DataSet
            Dim objDataAdapter as OleDBDataAdapter

            objDataAdapter = New OleDBDataAdapter("Select KampID, SpillerID, Spilletid from Boers", objConnection)

            objDataSet = New DataSet()
            objDataAdapter.Fill(objDataSet, "Boers")

            grdBoers.DataSource = objDataSet
            grdBoers.DataBind()

            objDataAdapter = Nothing
            objDataSet = Nothing
        End Sub

        Sub EditGridData(Sender as Object, E as DataGridCommandEventArgs)
            grdBoers.EditItemIndex = CInt(E.Item.ItemIndex)
            BindGrid()
        End Sub

        Sub CancelGridData(Sender as Object, E as DataGridCommandEventArgs)
            grdBoers.EditItemIndex = -1
            BindGrid()
        End Sub

        Sub UpdateGridData(Sender as Object, E as DataGridCommandEventArgs)
            Dim objCommand as OleDBCommand
            Dim objTextBox as TextBox

            Dim strSQL as String = "UPDATE Boers SET Spilletid = @Spilletid WHERE KampID = @KampID AND SpillerID = @SpillerID"

            objCommand = New Oledbcommand(strSQL, objConnection)

            objCommand.Parameters.Add(New OleDbParameter("@KampID", OleDBType.Integer, 10))
            objCommand.Parameters.Add(New OleDbParameter("@SpillerID", OleDBType.Integer, 10))
            objCommand.Parameters.Add(New OleDbParameter("@Spilletid", OleDbType.Integer, 2))

            objCommand.Parameters("@KampID").Value = grdBoers.DataKeys(CInt(E.Item.ItemIndex))

            objCommand.Parameters("@SpillerID").Value = grdBoers.DataKeys(CInt(E.Item.ItemIndex))

            objTextBox = E.Item.FindControl("edit_spilletid")
            objCommand.Parameters("@Spilletid").Value = objTextBox.Text

            objCommand.Connection.Open()

            objCommand.ExecuteNonQuery()

            grdBoers.EditItemIndex = -1

            objCommand.Connection.Close()

            BindGrid()

            objCommand = Nothing
            objTextBox = Nothing
        End Sub


        </SCRIPT>
    </HEAD>
    <BODY ms_positioning="FlowLayout">
        <FORM>
            <ASP:DATAGRID id="grdBoers" runat="server" headerstyle-forecolor="White" headerstyle-font-bold="true" headerstyle-backcolor="Maroon" gridlines="None" font-size="8pt" font-names="Verdana" datakeyfield="kampID" cellpadding="3" backcolor="White" autogeneratecolumns="false" alternatingitemstyle-backcolor="whitesmoke" onupdatecommand="UpdateGridData" oncancelcommand="CancelGridData" oneditcommand="EditGridData"></ASP:DATAGRID>
            <COLUMNS>
                <ASP:EDITCOMMANDCOLUMN itemstyle-wrap="False" updatetext="Update Row" canceltext="Cancel Edit" edittext="Edit Row" />
                <ASP:BOUNDCOLUMN visible="False" datafield="kampID" />
                <ASP:BOUNDCOLUMN visible="False" datafield="SpillerID" />
                <ASP:TEMPLATECOLUMN itemstyle-wrap="False" headertext="Spille tid" datafield="Spilletid">
                    <ITEMTEMPLATE>
                        <ASP:LABEL id=Spilletid runat="server" text='<%# DataBinder.Eval(Container.DataItem, "Spilletid", "{0:c}") %>'>
                        </ASP:LABEL>
                    </ITEMTEMPLATE>
                    <EDITITEMTEMPLATE>
                        <ASP:TEXTBOX id=edit_spilletid runat="server" font-size="8pt" text='<%# DataBinder.Eval(Container.DataItem, "Spilletid", "{0:c}") %>' width="100" font-name="Verdana">
                        </ASP:TEXTBOX>
                    </EDITITEMTEMPLATE>
                </ASP:TEMPLATECOLUMN>
                <ASP:BOUNDCOLUMN itemstyle-wrap="False" headertext="Nr." datafield="Nummer" />
            </COLUMNS></FORM>
    </BODY>
</HTML>
 
Old April 8th, 2004, 01:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Are you still having problems with this code?

XUMUSKIEFAN
Wrox Moderator
 
Old April 13th, 2004, 03:16 AM
Registered User
 
Join Date: Mar 2004
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Quote:
quote:Originally posted by xumuskiefan
 Are you still having problems with this code?

XUMUSKIEFAN
Wrox Moderator
Yes...

BB

 
Old May 11th, 2004, 12:32 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 124
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Let me look and see if I can find any errata for this code. Which book do you have? ISBN preferred.

XUMUSKIEFAN
Wrox Moderator





Similar Threads
Thread Thread Starter Forum Replies Last Post
Chapter 17 problem twr195 BOOK: Beginning ASP 3.0 0 May 25th, 2006 09:34 AM
Chapter 17 - Datagrid Updates Project ydv BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 December 27th, 2005 09:06 AM
Chapter 17 - DataGrid Sorting Example Appled BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 4 March 28th, 2005 03:13 PM
DataGrid Updates BLANK PAGE (Chapter 17) happyhorseygal BOOK: Beginning VB.NET 2nd Edition/Beginning VB.NET 2003 1 April 8th, 2004 01:11 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.