I love learning new things and not understanding them. I have a script and don't understand why it isn't working. The word Source works with the others? Like I said I am a newbee
<%@ import Namespace="System.Data.sqlClient" %>
<%@ import Namespace="System.Data" %>
<%@ Page Language="vb" Debug="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Lets give it a try</title>
<script runat="server">
Public Sub Page_Load(Source as Object, E As EventArgs)
if Not Page.IsPostBack Then
BindData( "Name" )
End If
End Sub
Public Sub BindData( strSortField As String)
Dim myDataSet as New DataSet
Dim mySqlDataAdapter as SqlDataAdapter
mySqlDataAdapter = New SqlDataAdapter( _
"SELECT * FROM Person order by " & strSortField, _
"server=AM1ST_FS1;database=HRINFO;uid=sa;"
mySqlDataAdapter.Fill(myDataSet, "Person"
PersonInfo.DataSource = myDataSet.Tables("Person"
PersonInfo.DataBind()
End Sub
public DataGrid_Sort(Source As Object, E As DataGridSortCommandEventArgs)
BindData( E.SortExpression )
End Sub
Public Sub DataGrid_Edit(Source As Object, E As DataGridCommandEventArgs)
personInfo.EditItemIndex= E.Item.ItemIndex
BindData()
End Sub
Public Sub DataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
personInfo.EditItemIndex = -1
BindData()
End Sub
Public Sub DataGrid_Update(Source As Object, E As DataGridCommandEventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim txtName As Textbox = E.Item.Cells(2).Controls(0)
Dim txtAddress As Textbox = E.Item.Cells(3).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt = "UPDATE Person SET Name = '" & txtName.Text & "', Address = '" & txtAddress.Text & "' WHERE ID = " & E.Item.Cells(1).Text
myConnection = New SqlConnection("server=AM1ST_FS1;database=HRINFO;uid=sa"
myCommand = new SqlCommand(strUpdateStmt, myConnection)
myConnection.open()
myCommand.ExecuteNonQuery()
personInfo.EditItemIndex = -1
BindData()
End Sub
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Editing Records in The DataGrid</h3>
<aspataGrid id="PersonInfo" Runat="server"
AlternatingItemStyle-BackColor="#A6F4FD"
AutoGeneratecolumns="false"
onEditCommand="DataGrid_Edit"
onCancelCommand="DataGrid_Cancel"
onUpdateCommand="DataGrid_Update"
AllowSorting="true"
onSortCommand="DataGrid_Sort">
<columns>
<asp:editcommandcolumn
ButtonType="LinkButton"
CancelText="Cancel"
editText="Edit"
UpdateText="Update" />
<asp:boundcolumn
DataField="ID"
HeaderText="ID"
ReadOnly="true" />
<asp:boundcolumn
DataField="Name"
HeaderText="Name" />
<asp:boundcolumn
DataField="Address"
HeaderText="Address" />
</columns>
</aspataGrid>
</form>
</body>
</HTML>
and I am getting the following error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'Source' is not declared.
Source Error:
Line 24: End Sub
Line 25:
Line 26: public DataGrid_Sort(Source As Object, E As DataGridSortCommandEventArgs)
Line 27: BindData( E.SortExpression )
Line 28: End Sub
<%@ import Namespace="System.Data.sqlClient" %>
<%@ import Namespace="System.Data" %>
<%@ Page Language="vb" Debug="true" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<title>Lets give it a try</title>
<script runat="server">
Public Sub Page_Load(Source as Object, E As EventArgs)
if Not Page.IsPostBack Then
BindData( "Name" )
End If
End Sub
Public Sub BindData( strSortField As String)
Dim myDataSet as New DataSet
Dim mySqlDataAdapter as SqlDataAdapter
mySqlDataAdapter = New SqlDataAdapter( _
"SELECT * FROM Person order by " & strSortField, _
"server=AM1ST_FS1;database=HRINFO;uid=sa;"
mySqlDataAdapter.Fill(myDataSet, "Person"
PersonInfo.DataSource = myDataSet.Tables("Person"
PersonInfo.DataBind()
End Sub
public DataGrid_Sort(Source As Object, E As DataGridSortCommandEventArgs)
BindData( E.SortExpression )
End Sub
Public Sub DataGrid_Edit(Source As Object, E As DataGridCommandEventArgs)
personInfo.EditItemIndex= E.Item.ItemIndex
BindData()
End Sub
Public Sub DataGrid_Cancel(Source As Object, E As DataGridCommandEventArgs)
personInfo.EditItemIndex = -1
BindData()
End Sub
Public Sub DataGrid_Update(Source As Object, E As DataGridCommandEventArgs)
Dim myConnection As SqlConnection
Dim myCommand As SqlCommand
Dim txtName As Textbox = E.Item.Cells(2).Controls(0)
Dim txtAddress As Textbox = E.Item.Cells(3).Controls(0)
Dim strUpdateStmt As String
strUpdateStmt = "UPDATE Person SET Name = '" & txtName.Text & "', Address = '" & txtAddress.Text & "' WHERE ID = " & E.Item.Cells(1).Text
myConnection = New SqlConnection("server=AM1ST_FS1;database=HRINFO;uid=sa"
myCommand = new SqlCommand(strUpdateStmt, myConnection)
myConnection.open()
myCommand.ExecuteNonQuery()
personInfo.EditItemIndex = -1
BindData()
End Sub
</script>
</HEAD>
<body>
<form id="Form1" method="post" runat="server">
<h3>Editing Records in The DataGrid</h3>
<aspataGrid id="PersonInfo" Runat="server"
AlternatingItemStyle-BackColor="#A6F4FD"
AutoGeneratecolumns="false"
onEditCommand="DataGrid_Edit"
onCancelCommand="DataGrid_Cancel"
onUpdateCommand="DataGrid_Update"
AllowSorting="true"
onSortCommand="DataGrid_Sort">
<columns>
<asp:editcommandcolumn
ButtonType="LinkButton"
CancelText="Cancel"
editText="Edit"
UpdateText="Update" />
<asp:boundcolumn
DataField="ID"
HeaderText="ID"
ReadOnly="true" />
<asp:boundcolumn
DataField="Name"
HeaderText="Name" />
<asp:boundcolumn
DataField="Address"
HeaderText="Address" />
</columns>
</aspataGrid>
</form>
</body>
</HTML>
and I am getting the following error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: BC30451: Name 'Source' is not declared.
Source Error:
Line 24: End Sub
Line 25:
Line 26: public DataGrid_Sort(Source As Object, E As DataGridSortCommandEventArgs)
Line 27: BindData( E.SortExpression )
Line 28: End Sub