Update of Datagrid after delete

G

Guest

Greeting

I am using the following code to delete a row from a datagrid
----------------
Private Sub dgClientTypes_DeleteCommand(ByVal source As Object, ByVal e As System.Web.UI.WebControls.DataGridCommandEventArgs) Handles dgClientTypes.DeleteComman

cmdClientTypes.CommandText = "Delete from tbClientTypes where (ClientTypeID = @ClientTypeID)

cmdClientTypes.Parameters.Add("@ClientTypeID", SqlDbType.SmallInt
cmdClientTypes.Parameters("@ClientTypeID").Value = dgClientTypes.DataKeys(CInt(e.Item.ItemIndex)

conFRSH.Open(
cmdClientTypes.ExecuteNonQuery(
conFRSH.Close(

dgClientTypes.DataSource = DsClientTypes
dgClientTypes.DataBind(
End Su

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Loa
'Put user code to initialize the page her
SqlDataAdapter1.Fill(DsClientTypes1
If Not IsPostBack The
dgClientTypes.DataBind(
End I

End Su
 
G

Guest

You're executing your query to delete the records but not refreshing you DsClientTypes1 dataset.

I usually code two methods for my dataset/datagrid DataGrid_Fill and DataGrid_Bind. Call DataGrid_Fill after you make modifications to the database and want to refresh the dataset/datatable for the grid. Call DataGrid_Bind when you just want to add a RowSelect for sorting/filtering/etc. on a dataview
I.E

Protected Sub dgClientTypes_Fill(
'Put code to fill the dataset using a dataadapte
Dim oDa as New SqlClient.SqlDataAdapte
...
oDa.Fill(DsClientTypes1
Session("vClientTypes") = New DataView(DsClientTypes1

End Su

Protected Sub dgClientTypes_Bind(
'Put code to bind up the datagri
Dim v As DataView = DirectCast(Session("vClientTypes"),dataview
'Do any RowFilter her

dgClientTypes.DataSource =
dgClientTypes.DataBind(
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,043
Latest member
CannalabsCBDReview

Latest Threads

Top