Update of Datagrid after delete

Discussion in 'ASP .Net' started by =?Utf-8?B?S2FzaGlmIE1laG1vb2Q=?=, Jun 3, 2004.

  1. 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
    --------------

    The problem is that the page is not showing updated values after the change. Help would be appreciated. Thanks in advance

    Regards
    =?Utf-8?B?S2FzaGlmIE1laG1vb2Q=?=, Jun 3, 2004
    #1
    1. Advertising

  2. 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
    =?Utf-8?B?bmF0WA==?=, Jun 3, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mark
    Replies:
    2
    Views:
    2,224
  2. =?Utf-8?B?TWljaGFlbA==?=

    How to update datagrid after update

    =?Utf-8?B?TWljaGFlbA==?=, Mar 17, 2006, in forum: ASP .Net
    Replies:
    1
    Views:
    499
    Alex D.
    Mar 17, 2006
  3. Andreas Klemt
    Replies:
    0
    Views:
    292
    Andreas Klemt
    Oct 8, 2003
  4. Fred Zolar
    Replies:
    0
    Views:
    220
    Fred Zolar
    Apr 1, 2004
  5. Stephan Kämper
    Replies:
    1
    Views:
    142
    Assaph Mehr
    Jul 15, 2006
Loading...

Share This Page