This is a migrated thread and some comments may be shown as answers.

Why i can't delete ??

3 Answers 83 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Edmond Junior
Top achievements
Rank 1
Edmond Junior asked on 02 Mar 2009, 06:28 PM
I am trying to delete a register from my grid using this but nothing happens !!! My Database is a mdb file (Access)

   Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.DeleteCommand 
        Dim objConn1 As OleDbConnection 
        Dim strCaminho As String = Server.MapPath("~/adm/bd/observatorio.mdb") 
        objConn1 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strCaminho & ";") 
        Dim SqlCommand As New OleDbCommand() 
        'Get the GridDataItem of the RadGrid 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
        'Get the primary key value using the DataKeyValue. 
        Dim NEWSID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("news_id").ToString() 
        Try 
            'Open the SqlConnection 
            objConn1.Open() 
            Try 
                Dim deleteQuery As String = "DELETE from tblNoticias where news_id='" & NEWSID & "'" 
                SqlCommand.CommandText = deleteQuery 
                SqlCommand.Connection = objConn1 
                SqlCommand.ExecuteNonQuery() 
                'Close the SqlConnection 
                objConn1.Close() 
            Catch ex As Exception 
                Response.Write(ex.Message) 
                'Me.lblError.Text = "Ocorreu um erro na tentativa de excluir o registro !" 
                Exit Sub 
            End Try 
        Catch ex As Exception 
            Me.lblError.Text = "Não foi possível abrir o banco de dados" 
            Exit Sub 
        End Try 
    End Sub 
 when i click in delete link nothing happens....

any help ???

Thanks
Jr

3 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 03 Mar 2009, 05:34 AM
Hi Edmond,

Can you check whether you have set the AllowAutomaticDeletes property to true for the Grid. If so try setting it to false and see whether it is working fine.

Shinu
0
Edmond Junior
Top achievements
Rank 1
answered on 03 Mar 2009, 11:45 AM
Hi Shinu,
 i trid what you said and nothing happens. Below the complete code (aspx and vb) ..

%@ Page Language="VB" MasterPageFile="~/master/MasterPage.master" AutoEventWireup="false" CodeFile="editarnews.aspx.vb" Inherits="adm_editarnews" title="Untitled Page" %> 
 
<%@ Register assembly="RadGrid.Net2" namespace="Telerik.WebControls" tagprefix="radG" %> 
 
<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server"
</asp:Content> 
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server"
    <div align="center"><asp:Label ID="lblError" runat="server" Font-Bold="True"  
            ForeColor="Red" /></div
    <br /> 
    <radG:RadGrid ID="RadGrid1" runat="server" AllowPaging="True" AutoGenerateColumns="False" 
        OnDeleteCommand="RadGrid1_DeleteCommand" OnNeedDataSource="RadGrid1_NeedDataSource" 
        EnableAJAX="True" GridLines="None" PageSize="3"  
        EnableAJAXLoadingTemplate="True"
        <MasterTableView DataKeyNames="news_id"
            <RowIndicatorColumn Visible="False"
                <HeaderStyle Width="20px"></HeaderStyle> 
            </RowIndicatorColumn> 
            <ExpandCollapseColumn Visible="False"
                <HeaderStyle Width="19px"></HeaderStyle> 
            </ExpandCollapseColumn> 
            <Columns> 
                <radG:GridBoundColumn DataField="news_id" DataType="System.Int32" HeaderText="news_id" 
                    ReadOnly="True" SortExpression="news_id" UniqueName="news_id" Visible="False"
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="news_dtinclusao" DataFormatString="{0:dd/MM/yyyy}" 
                    DataType="System.DateTime" HeaderText="Data" SortExpression="news_dtinclusao" 
                    UniqueName="news_dtinclusao"
                    <ItemStyle CssClass="fonte_menor" Width="80px" /> 
                </radG:GridBoundColumn> 
                <radG:GridBoundColumn DataField="news_titulo" HeaderText="Título" SortExpression="news_titulo" 
                    UniqueName="news_titulo"
                </radG:GridBoundColumn> 
                <radG:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="Delete" 
                    ConfirmText="Deseja excluir esse registro ?"
                </radG:GridButtonColumn> 
            </Columns> 
        </MasterTableView> 
        <ClientSettings> 
            <Selecting AllowRowSelect="True" /> 
        </ClientSettings> 
    </radG:RadGrid> 
     
     
</asp:Content> 
and the code behind:

Imports System.Data 
Imports System.Data.OleDb 
Imports Telerik.WebControls 
 
Partial Class adm_editarnews 
    Inherits System.Web.UI.Page 
    Public Shared dtTable As DataTable 
    Public SqlDataAdapter As New OleDbDataAdapter() 
 
    Protected Sub RadGrid1_NeedDataSource(ByVal source As Object, ByVal e As Telerik.WebControls.GridNeedDataSourceEventArgs) Handles RadGrid1.NeedDataSource 
        Dim objConn As OleDbConnection 
        Dim strCaminho As String = Server.MapPath("~/adm/bd/observatorio.mdb") 
        objConn = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strCaminho & ";") 
        dtTable = New DataTable() 
        Try 
            objConn.Open() 
 
            Try 
                'Popula o grid com dados da Tabela Noticias. 
                Dim selectQuery As String = "Select distinct news_id,news_titulo,news_dtinclusao from tblNoticias order by news_dtinclusao desc" 
                SqlDataAdapter.SelectCommand = New OleDbCommand(selectQuery, objConn) 
                SqlDataAdapter.Fill(dtTable) 
                RadGrid1.DataSource = dtTable 
            Catch ex As Exception 
                Me.lblError.Text = "Ocorreu um erro na tentativa de carregar os dados !" 
                'Me.lblError.Text = ex.Message 
                Exit Sub 
            Finally 
                'Close the SqlConnection 
                objConn.Close() 
            End Try 
 
        Catch ex As Exception 
            Me.lblError.Text = "Não foi possível abrir o banco de dados" 
            Exit Sub 
        End Try 
    End Sub 
 
    Protected Sub RadGrid1_DeleteCommand(ByVal source As Object, ByVal e As Telerik.WebControls.GridCommandEventArgs) Handles RadGrid1.DeleteCommand 
        Dim objConn1 As OleDbConnection 
        Dim strCaminho As String = Server.MapPath("~/adm/bd/observatorio.mdb") 
        objConn1 = New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & strCaminho & ";") 
        Dim SqlCommand As New OleDbCommand() 
        'Get the GridDataItem of the RadGrid 
        Dim item As GridDataItem = DirectCast(e.Item, GridDataItem) 
        'Get the primary key value using the DataKeyValue. 
        Dim NEWSID As String = item.OwnerTableView.DataKeyValues(item.ItemIndex)("news_id").ToString() 
        Try 
            'Open the SqlConnection 
            objConn1.Open() 
            Try 
                Dim deleteQuery As String = "DELETE from tblNoticias where news_id='" & NEWSID & "'" 
                SqlCommand.CommandText = deleteQuery 
                SqlCommand.Connection = objConn1 
                SqlCommand.ExecuteNonQuery() 
                'Close the SqlConnection 
                objConn1.Close() 
            Catch ex As Exception 
                Response.Write(ex.Message) 
                'Me.lblError.Text = "Ocorreu um erro na tentativa de excluir o registro !" 
                Exit Sub 
            End Try 
        Catch ex As Exception 
            Me.lblError.Text = "Não foi possível abrir o banco de dados" 
            Exit Sub 
        End Try 
    End Sub 
 
End Class 

can you help me what's wrong ?

Thanks
Junior







0
Edmond Junior
Top achievements
Rank 1
answered on 05 Mar 2009, 01:51 PM
Hi Shinu, give me a help please if you can...

Tks
Junior
Tags
Grid
Asked by
Edmond Junior
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Edmond Junior
Top achievements
Rank 1
Share this question
or