LadyGail Posted February 24, 2004 Posted February 24, 2004 (edited) I need to edit a datagrid. I am using Visual Studio.NET for my development tool. I have an .aspx, .aspx.vb and a .vb page. My .aspx page has the data grid with: OnEditCommand="dgrdDivision_EditCommand" OnUpdateCommand="dgrdDivision_UpdateCommand" OnCancelCommand="dgrdDivision_CancelCommand" and an EditCommandColumn corresponding to the edit, update and cancel features. In my class file I have a function: Public Function InsertIntoDivisionDb(ByVal dgrdDivision As DataGrid) As clDivision BindDataGrid() dgrdDivision_EditCommand() dgrdDivision_UpdateCommand() End Function I am calling the sub routines which hold the connection string, edit code:dgrdDivision.EditItemIndex = e.Item.ItemIndex. And the third sub routine has the update code: Sub dgrdDivision_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Dim txtDivisionCode As TextBox Dim txtDivisionName As TextBox Dim strDivisionCode As String Dim strDivisionName As String Dim conn As SqlConnection = openDatabase() txtDivisionCode = dgrdDivision.DataKeys(e.Item.ItemIndex) txtDivisionCode = e.Item.Cells(0).Controls(0) txtDivisionName = e.Item.Cells(1).Controls(0) strDivisionCode = txtDivisionCode.Text strDivisionName = txtDivisionName.Text strSQL = "Update DivisionCode Set DivisionCode=@DivCode, " _ & "DivisionName=@TrackingDivisionName Where DivisionCode=@DivisionCode" cmdSQL = New SqlCommand(strSQL, conn) cmdSQL.Parameters.Add("@DivisionCode", strDivisionCode) cmdSQL.Parameters.Add("@DivisionName", strDivisionName) openDatabase() cmdSQL.ExecuteNonQuery() closeDatabase(conn) BindDataGrid() dgrdDivision.EditItemIndex = -1 End Sub The error reads: BC30456: 'dgrdDivision_EditCommand' is not a member of 'ASP.UpdateDivisionInfo_aspx'. I don't understant the error as I have the sub routine dgrdDivision_EditCommand. What am I a not seeing? Thank you. Edited February 24, 2004 by Robby Quote
Moderators Robby Posted February 24, 2004 Moderators Posted February 24, 2004 You don't have a sub called 'dgrdDivision_EditCommand' Where are you calling 'InsertIntoDivisionDb()' from ? And why are you calling the Edit and Update from it? The Update, Edit, Delete are supposed to be called after the user clicks then posts back of there asigned controls. Quote Visit...Bassic Software
LadyGail Posted February 24, 2004 Author Posted February 24, 2004 On my .vb page within the class I have sub titled: Sub dgrdDivision_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) dgrdDivision.EditItemIndex = e.Item.ItemIndex BindDataGrid() End Sub On my .aspx.vb page I have the following: 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 Dim DivisionName As New clDivision() If Not IsPostBack Then DivisionName.InsertIntoDivisionDb(dgrdDivision) End If End Sub Quote
Moderators Robby Posted February 24, 2004 Moderators Posted February 24, 2004 This function..... Public Function InsertIntoDivisionDb(ByVal dgrdDivision As DataGrid) As clDivision BindDataGrid() dgrdDivision_EditCommand() dgrdDivision_UpdateCommand() End Function ...makes no sense at all, you're passing in the datagrid but you don't use it and the function is supposed to return a Class but it does not return anything. I suggest just changing the Page load event to the following .... Private Sub Page_Load(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then BindDataGrid() End If End Sub Quote Visit...Bassic Software
LadyGail Posted February 24, 2004 Author Posted February 24, 2004 I made the changes you stated and I get the error message: 'dgrdDivision_EditCommand' is not a member of 'ASP.UpdateDivisionInfo_aspx'. Quote
email_smdd_here Posted February 24, 2004 Posted February 24, 2004 Sounds like your missing code in the HTML part of your page. Open your aspx page and then click the HTML tag on the bottom. This will show you the code for your design. For your datagrid you should have something like... <asp:datagrid id="YOURGRIDNAMEHERE" style="Z-INDEX: 101; LEFT: 0px; POSITION: absolute; TOP: 1px" runat="server" OnEditCommand="dgrdDivision_EditCommand"> Then you need to setup an edit bound column which I'm assuming you did. Then save, click back to Design and double click to access your vb code. Then you'll need something like Sub grdDivision_EditCommand(ByVal sender As Object, ByVal e As DataGridCommandEventArgs) What ever you want it to do goes here End sub Quote
Moderators Robby Posted February 24, 2004 Moderators Posted February 24, 2004 David, the error is due to having 'OnEditCommand="dgrdDivision_EditCommand" ' in the aspx page and not having the event/routine in the class/code-behind. Quote Visit...Bassic Software
LadyGail Posted February 25, 2004 Author Posted February 25, 2004 I made the suggested changes and things are now worst. I freely confess that I am not certain as to how to implement the correct solution. As such, I am posting my code for a) my web form, .aspx; and b) the code behind file, .aspx.vb. Would you please let me know what to do? Thank you, so very kindly. LadyGail WebForm-.ASPX <%@ Page Language="vb" AutoEventWireup="false" Codebehind="UpdateDivisionInfo.aspx.vb" Inherits="TestGale411.UpdateDivisionInfo"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD> <title>UpdateDivisionInfo</title> <meta content="Microsoft Visual Studio.NET 7.0" name="GENERATOR"> <meta content="Visual Basic 7.0" name="CODE_LANGUAGE"> <meta content="JavaScript" name="vs_defaultClientScript"> <meta content="http://schemas.microsoft.com/intellisense/ie5" name="vs_targetSchema"> </HEAD> <body MS_POSITIONING="GridLayout"> <form id="Form1" method="post" runat="server"> <asp:label id="Label1" style="Z-INDEX: 101; LEFT: 122px; POSITION: absolute; TOP: 57px" runat="server" Font-Bold="True" Font-Size="Large">Update Division Information</asp:label> <asp:datagrid id="dgrdDivision" style="Z-INDEX: 102; LEFT: 129px; POSITION: absolute; TOP: 103px" runat="server" HeaderStyle-BackColor="Salmon" CellPadding="10" AutoGenerateColumns="False" DataKeyField="DivCode" OnCancelCommand="dgrdDivision_CancelCommand" OnUpdateCommand="dgrdDivision_UpdateCommand" OnEditCommand="dgrdDivision_EditCommand" Height="206px" Width="350px"> <Columns> <asp:BoundColumn HeaderText="Division Code" DataField="DivCode" /> <asp:BoundColumn HeaderText="Division Name" DataField="TrackingDivisionName" /> <asp:EditCommandColumn EditText="Edit!" UpdateText="Update!" CancelText="Cancel!" /> </Columns> </asp:datagrid></form> </body> </HTML> ************************************************** CODE BEHIND FILE-.ASPX.VB Imports System.Data Imports System.Data.SqlClient Public Class UpdateDivisionInfo Inherits System.Web.UI.Page Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents dgrdDivision As System.Web.UI.WebControls.DataGrid Dim DivCode As String Dim DivName As String Dim strSQL As String #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 Dim DivisionName As New clDivision() If Not IsPostBack Then DivisionName.BindDataGrid() End If End Sub Sub dgrdDivision_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) dgrdDivision.EditItemIndex = e.Item.ItemIndex End Sub Sub dgrdDivision_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Dim txtDivisionCode As TextBox Dim txtDivisionName As TextBox Dim strDivisionCode As String Dim strDivisionName As String Dim conn As SqlConnection = openDatabase() txtDivisionCode = dgrdDivision.DataKeys(e.Item.ItemIndex) txtDivisionCode = e.Item.Cells(0).Controls(0) txtDivisionName = e.Item.Cells(1).Controls(0) strDivisionCode = txtDivisionCode.Text strDivisionName = txtDivisionName.Text strSQL = "Update DivisionCode Set DivisionCode=@DivCode, " _ & "DivisionName=@TrackingDivisionName Where DivisionCode=@DivisionCode" cmdSQL = New SqlCommand(strSQL, conn) cmdSQL.Parameters.Add("@DivisionCode", strDivisionCode) cmdSQL.Parameters.Add("@DivisionName", strDivisionName) openDatabase() cmdSQL.ExecuteNonQuery() closeDatabase(conn) BindDataGrid() dgrdDivision.EditItemIndex = -1 End Sub Public Function openDatabase() Dim conn As New SqlConnection _ ("data source=S0960028;initial catalog=POWER;user id=gu;password=wasdall") Return conn End Function Private Function closeDatabase(ByVal conn) conn.close() conn = Nothing End Function End Class Quote
Administrators PlausiblyDamp Posted February 25, 2004 Administrators Posted February 25, 2004 try changing the update and command handlers so they include the handles keyword (see below). Couldn't test the code though as the bit you posted doesn't contain a variable called cmdSQL or a function called BindDataGrid. Sub dgrdDivision_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgrdDivision.EditCommand dgrdDivision.EditItemIndex = e.Item.ItemIndex End Sub Sub dgrdDivision_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgrdDivision.UpdateCommand Dim txtDivisionCode As TextBox Dim txtDivisionName As TextBox Dim strDivisionCode As String Dim strDivisionName As String Dim conn As SqlConnection = openDatabase() txtDivisionCode = dgrdDivision.DataKeys(e.Item.ItemIndex) txtDivisionCode = e.Item.Cells(0).Controls(0) txtDivisionName = e.Item.Cells(1).Controls(0) strDivisionCode = txtDivisionCode.Text strDivisionName = txtDivisionName.Text strSQL = "Update DivisionCode Set DivisionCode=@DivCode, " _ & "DivisionName=@TrackingDivisionName Where DivisionCode=@DivisionCode" cmdSQL = New SqlCommand(strSQL, conn) cmdSQL.Parameters.Add("@DivisionCode", strDivisionCode) cmdSQL.Parameters.Add("@DivisionName", strDivisionName) openDatabase() cmdSQL.ExecuteNonQuery() closeDatabase(conn) BindDataGrid() dgrdDivision.EditItemIndex = -1 End Sub Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
LadyGail Posted February 25, 2004 Author Posted February 25, 2004 My error for not including all of the file contents. This has the BindDataGrid(). I made the changes you suggested and now am getting the following error: Compiler Error Message: BC30456: 'dgrdDivision_EditCommand' is not a member of 'ASP.UpdateDivisionInfo_aspx'. Imports System.Data Imports System.Data.SqlClient Public Class UpdateDivisionInfo Inherits System.Web.UI.Page Protected WithEvents Label1 As System.Web.UI.WebControls.Label Protected WithEvents dgrdDivision As System.Web.UI.WebControls.DataGrid Dim DivCode As String Dim DivName As String Dim strSQL As String Dim cmdSQL As SqlCommand #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 Dim DivisionName As New clDivision() If Not IsPostBack Then DivisionName.BindDataGrid() End If End Sub Sub BindDataGrid() Dim conn As SqlConnection = openDatabase() cmdSQL = New SqlCommand("Select * from DivisionCode", conn) conn.Open() dgrdDivision.DataSource = cmdSQL.ExecuteReader() dgrdDivision.DataBind() conn.Close() End Sub Sub dgrdDivision_EditCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgrdDivision.EditCommand dgrdDivision.EditItemIndex = e.Item.ItemIndex End Sub Sub dgrdDivision_UpdateCommand(ByVal s As Object, ByVal e As DataGridCommandEventArgs) Handles dgrdDivision.UpdateCommand Dim txtDivisionCode As TextBox Dim txtDivisionName As TextBox Dim strDivisionCode As String Dim strDivisionName As String Dim conn As SqlConnection = openDatabase() txtDivisionCode = dgrdDivision.DataKeys(e.Item.ItemIndex) txtDivisionCode = e.Item.Cells(0).Controls(0) txtDivisionName = e.Item.Cells(1).Controls(0) strDivisionCode = txtDivisionCode.Text strDivisionName = txtDivisionName.Text strSQL = "Update DivisionCode Set DivisionCode=@DivCode, " _ & "DivisionName=@TrackingDivisionName Where DivisionCode=@DivisionCode" cmdSQL = New SqlCommand(strSQL, conn) cmdSQL.Parameters.Add("@DivisionCode", strDivisionCode) cmdSQL.Parameters.Add("@DivisionName", strDivisionName) openDatabase() cmdSQL.ExecuteNonQuery() closeDatabase(conn) BindDataGrid() dgrdDivision.EditItemIndex = -1 End Sub Public Function openDatabase() Dim conn As New SqlConnection _ ("data source=S0960028;initial catalog=POWER;user id=gu;password=wasdall") Return conn End Function Private Function closeDatabase(ByVal conn) conn.close() conn = Nothing End Function End Class Quote
Administrators PlausiblyDamp Posted February 25, 2004 Administrators Posted February 25, 2004 Pasting your code in I don't get any errors with regards to dgrdDivision_EditCommand' is not a member of 'ASP.UpdateDivisionInfo_aspx'. but I didn't expect to. Not having your DB I can't test this but I really don't know why you got that error. Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
LadyGail Posted February 25, 2004 Author Posted February 25, 2004 The db table I am using consists of: DivCode TrackingDivisionName 10 Controller 16 MIS 20 Engineering It is running on MS SQL Server. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.