Imports System.Data.SqlClient Imports System.Data PartialClass CategoryClass Category Inherits System.Web.UI.Page ProtectedSub Page_Load()Sub Page_Load(ByVal sender AsObject, ByVal e As System.EventArgs) HandlesMe.Load If (Me.Session("Admin") <>"admin") Then Me.Response.Redirect("login.aspx") EndIf End Sub ProtectedSub gvResult_RowDeleting()Sub gvResult_RowDeleting(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvResult.RowDeleting Dim CategoryID AsInteger= e.Keys("CategoryID") Dim conn AsNew SqlConnection conn.ConnectionString = ConfigurationManager.ConnectionStrings("TNTConnectionString").ConnectionString conn.Open() Dim comm AsNew SqlCommand comm.Connection = conn comm.CommandText ="DELETE FROM Item WHERE CategoryID=@CategoryID" comm.Parameters.AddWithValue("@CategoryID", CategoryID) comm.ExecuteNonQuery() comm.Dispose() conn.Close() conn.Dispose() End Sub ProtectedSub btnAdd_Click()Sub btnAdd_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnAdd.Click Dim conn AsNew SqlConnection conn.ConnectionString = ConfigurationManager.ConnectionStrings("TNTConnectionString").ConnectionString conn.Open() Dim comm AsNew SqlCommand comm.Connection = conn comm.CommandText ="INSERT INTO Category(ChineseDescription,EnglishDescription) VALUES(@ChineseDescription,@EnglishDescription)" comm.Parameters.AddWithValue("@ChineseDescription", Me.txtChineseDescription.Text) comm.Parameters.AddWithValue("@EnglishDescription", Me.txtEnglishDescription.Text) comm.ExecuteNonQuery() comm.Dispose() conn.Close() conn.Dispose() Me.gvResult.DataBind() End Sub ProtectedSub sdsResult_Selecting()Sub sdsResult_Selecting(ByVal sender AsObject, ByVal e As System.Web.UI.WebControls.SqlDataSourceSelectingEventArgs) Handles sdsResult.Selecting Try If (NotString.IsNullOrEmpty(Me.chineseTextBox.Text)) Then e.Command.Parameters("@ChineseDescription").Value =Me.chineseTextBox.Text Else e.Command.Parameters("@ChineseDescription").Value = DBNull.Value EndIf Catch ex As Exception e.Command.Parameters("@ChineseDescription").Value = DBNull.Value EndTry Try If (NotString.IsNullOrEmpty(Me.englishTextBox.Text)) Then e.Command.Parameters("@EnglishDescription").Value =Me.englishTextBox.Text Else e.Command.Parameters("@EnglishDescription").Value = DBNull.Value EndIf Catch ex As Exception e.Command.Parameters("@EnglishDescription").Value = DBNull.Value EndTry End Sub ProtectedSub btnSearch_Click()Sub btnSearch_Click(ByVal sender AsObject, ByVal e As System.EventArgs) Handles btnSearch.Click Me.gvResult.DataBind() End Sub 'Protected Sub gvResult_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles gvResult.RowDataBound ' If (e.Row.RowType = DataControlRowType.DataRow) Then ' If (e.Row.RowState = DataControlRowState.Edit) Or (e.Row.RowState = DataControlRowState.Alternate + DataControlRowState.Edit) Then ' Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView) ' Dim txtChineseDescription As TextBox = CType(e.Row.FindControl("txtChineseDescription"), TextBox) ' txtChineseDescription.Text = drv("ChineseDescription") ' Dim txtEnglishDescription As TextBox = CType(e.Row.FindControl("txtEnglishDescription"), TextBox) ' txtEnglishDescription.Text = drv("EnglishDescription") ' ElseIf (e.Row.RowState = DataControlRowState.Normal) Or (e.Row.RowState = DataControlRowState.Normal + DataControlRowState.Alternate) Then ' Dim drv As DataRowView = CType(e.Row.DataItem, DataRowView) ' Dim lblChineseDescription As Label = CType(e.Row.FindControl("lblChineseDescription"), Label) ' lblChineseDescription.Text = drv("ChineseDescription") ' Dim lblEnglishDescription As Label = CType(e.Row.FindControl("lblEnglishDescription"), Label) ' lblEnglishDescription.Text = drv("EnglishDescription") ' End If ' End If 'End Sub End Class