tags:

views:

86

answers:

2
+1  Q: 

Asp.net Grid View

In my Grid View ,When a button is clicked,i want to insert that row in to database and at the same time make the row invisible in the Grid View. I can insert in to database but can't make the inserted row invisible.

        Dim PayID As Integer = (e.CommandArgument)
        Dim EmpID As Integer = (e.CommandArgument)
        Dim EID As Integer = CType(Dg1.DataKeys(EmpID).Values("EmpID"), Integer)
        Dim PID As Integer = CType(Dg1.DataKeys(PayID).Values("PayID"), Integer)

        cmd.CommandText = "Insert into EmployDetails(EmpID,PayID,PayDate) 
        Values(" & EID & " ," & PID & ",GetDate())"
        cmd.ExecuteNonQuery()

Thank You

+1  A: 

You might need to bind the GridView to a DataView instead of a DataSet. Then when you add a row update the DataView to exclude the new row.

Jonathan Parker
+1  A: 

After insering your row to db, you should remove the related record from datasource (datatable, dataview) and rebind your gridview.

EDIT :

After your Insert operation :

1. take your remove the related row from your datasource :

Dim insertedRows As DataRow() = myDataTable.Select("ID = " & id)

For Each dr As DataRow In insertedRows

    myDataTable.Rows.Remove(dr)

Next

2. And after that re-bind your gridview :

gridView.DataSource = myDataTable
gridView.DataBind()

NOTE : I use a converter to convert codes C# to VB. Hope it's ok.

Canavar
Thanks,But Can you please expand with codes
KSCD