PAGE SOURCE IS:
OnRowCancelingEdit="gvcategory_RowCancelingEdit"
OnRowDeleting="gvcategory_RowDeleting" OnRowEditing="gvcategory_RowEditing"
OnRowUpdating="gvcategory_RowUpdating"
BackColor="White" BorderColor="#999999" BorderStyle="None" BorderWidth="1px"
CellPadding="3" GridLines="Vertical" AllowPaging="True" Width="50%">
CODE BEHIND IS:
Imports System.Data.SqlClient
Imports System.Data
Partial Class management_add_category
Inherits System.Web.UI.Page
Dim obj As New data
Dim da As SqlDataAdapter
Dim ds As DataSet
Protected Sub btnadd_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnadd.Click
obj.Connect()
obj.cmd.CommandText = "insert into category_master(category_name)values('" & txtcategory.Text & "')"
obj.cmd.ExecuteNonQuery()
MsgBox("category added!", MsgBoxStyle.Information, "Mohire`s")
txtcategory.Text = ""
obj.db.Close()
fill_data()
End Sub
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
If Session("user_id") = "" Then
Response.Redirect("admin_login.aspx")
End If
fill_data()
End Sub
Private Sub fill_data()
obj.Connect()
obj.cmd.CommandText = "Select * from category_master order by category_id asc"
da = New SqlDataAdapter(obj.cmd)
ds = New DataSet
da.Fill(ds, "category_master")
gvcategory.DataSource = ds.Tables("category_master")
gvcategory.DataBind()
obj.db.Close()
End Sub
Protected Sub gvcategory_PageIndexChanging(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewPageEventArgs) Handles gvcategory.PageIndexChanging
gvcategory.PageIndex = e.NewPageIndex
fill_data()
End Sub
Protected Sub gvcategory_RowCancelingEdit(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewCancelEditEventArgs) Handles gvcategory.RowCancelingEdit
gvcategory.EditIndex = -1
fill_data()
End Sub
Protected Sub gvcategory_RowDeleting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewDeleteEventArgs) Handles gvcategory.RowDeleting
Dim l1 As Label = CType(gvcategory.Rows(e.RowIndex).FindControl("lblcatid"), Label)
obj.Connect()
obj.cmd.CommandText = "delete category_master where category_id=" & l1.Text & ""
obj.cmd.ExecuteNonQuery()
gvcategory.EditIndex = -1
MsgBox("category deleted!", MsgBoxStyle.Information, "Mohire`s")
obj.db.Close()
fill_data()
End Sub
Protected Sub gvcategory_RowEditing(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewEditEventArgs) Handles gvcategory.RowEditing
gvcategory.EditIndex = e.NewEditIndex
fill_data()
End Sub
Protected Sub gvcategory_RowUpdating(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewUpdateEventArgs) Handles gvcategory.RowUpdating
Try
Dim l1 As Label = CType(gvcategory.Rows(e.RowIndex).FindControl("lblcatid"), Label)
Dim txtcatname As TextBox = CType(gvcategory.Rows(e.RowIndex).FindControl("txtcategory"), TextBox)
obj.Connect()
obj.cmd.CommandText = "update category_master set category_name='" & txtcatname.Text & "' where category_id=" & l1.Text
obj.cmd.ExecuteNonQuery()
gvcategory.EditIndex = -1
MsgBox("category updated!", MsgBoxStyle.Information, "Mohire`s")
obj.db.Close()
Catch ex As Exception
MsgBox(ex.Message)
End Try
fill_data()
End Sub
End Class

Suthish NairPosted Dec 18, 2010, 1:08 AM
Anyway you got it resolved at last.
B M SuchitraPosted Dec 17, 2010, 10:25 PM
Suthish NairPosted Dec 17, 2010, 2:29 PM
B M SuchitraPosted Dec 17, 2010, 3:32 AM
I am not able to find where the error is ... So pasted the whole code so that you guys can atleast point out....
Manikavelu VelayuthamPosted Dec 17, 2010, 2:35 AM