the record is not deleted... what's wrong

iceberg100

New member
Joined
Mar 10, 2006
Messages
2
Programming Experience
1-3
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="MasterDetail.aspx.vb" Inherits="MasterDetail" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Master/Detail</title>
<script runat="server">

Sub Validate_Insert_Data(ByVal Src As Object, ByVal Args As DetailsViewInsertEventArgs)


If Args.Values("IDTable1") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Nema OZNAKE RN"
End If

If Args.Values("Ime") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Nema imena"
End If

If Args.Values("Prezime") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Nema prezimena"
End If
End Sub

Sub Display_Insert_Msg(ByVal Src As Object, ByVal Args As DetailsViewInsertedEventArgs)

EditMSG.Text = "-- ZAPIS POD OZNAKOM: " & Args.Values("IDTable1") & " DODAN"
Grid_Table1.DataBind()

End Sub


Sub Validate_Update_Data(ByVal Src As Object, ByVal Args As DetailsViewUpdateEventArgs)

If Args.NewValues("IDTable1") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Nema imena"
End If

If Args.NewValues("Ime") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Nema imena"
End If

If Args.NewValues("Prezime") = "" Then
Args.Cancel = True
EditMSG.Text = "-- Nema prezimena"
End If

End Sub

Sub Display_Update_Msg(ByVal Src As Object, ByVal Args As DetailsViewUpdatedEventArgs)
Grid_Table1.DataBind()
EditMSG.Text = "-- ZAPIS POD OZNAKOM: " & Args.Keys("IDTable1") & " PROMIJENJEN"

End Sub

Sub Confirm_Delete(ByVal Src As Object, ByVal Args As DetailsViewDeleteEventArgs)
MsgBox(Args.Keys("IDTable1"), MsgBoxStyle.OkOnly)
Args.Cancel = True
Dim ConfirmLabel As Label = Details_Table1.Rows(0).FindControl("ConfirmDelete")
ConfirmLabel.Visible = True
ViewState("IDTable1") = Args.Keys("IDTable1")

End Sub

Sub Get_Command(ByVal Src As Object, ByVal Args As DetailsViewCommandEventArgs)

If Args.CommandName = "Yes" Then

Data_Table1_detaljno.DeleteCommand = "DELETE FROM Table1 WHERE IDTable1 = '" & ViewState("IDTable1") & "'"
Grid_Table1.DataBind()
EditMSG.Text = " Record " & ViewState("IDTable1") & " deleted"
End If

End Sub

</script>
</head>
<body>
<form id="form1" runat="server">
<div>


<asp:AccessDataSource id="Data_Table1" Runat="Server" DataFile="C:\TOTIC.mdb"
SelectCommand="SELECT IDTable1, Ime, Prezime FROM Table1"/>

<asp:Label id="EditMSG" EnableViewState="False" ForeColor="Red" Runat="Server"/>

<asp:GridView id="Grid_Table1" DataSourceID="Data_Table1" Runat="Server"
DataKeyNames="IDTable1"
AutoGenerateColumns="False"
Width="250"
SelectedIndex="0"
SelectedRowStyle-BackColor="RED"
HeaderStyle-BackColor="#E0E0E0"
HeaderStyle-Font-Bold="True"
Style="float:left">
<Columns>

<asp:TemplateField HeaderText="OZNAKA" HeaderStyle-Width="50">
<ItemTemplate>
<asp:LinkButton ID="LinkButton1" CommandName="Select" Runat="Server">
<%#Eval("IDTable1")%>
</asp:LinkButton>
</ItemTemplate>
</asp:TemplateField>
<asp:BoundField HeaderText="Ime" DataField="Ime"/>
<asp:BoundField HeaderText="Prezime" DataField="Prezime"/>
</Columns>

</asp:GridView>


<asp:AccessDataSource id="Data_Table1_detaljno" Runat="Server" DataFile="C:\TOTIC.mdb"

SelectCommand="SELECT IDTable1, Ime, Prezime FROM Table1 WHERE IDTable1 = @IDTable1"

InsertCommand="INSERT INTO Table1 (IDTable1, Ime, Prezime) VALUES (@IDTable1, @Ime, @Prezime)"

UpdateCommand="UPDATE Table1 SET IDTable1=@IDTable1, Ime=@Ime, Prezime=@Prezime WHERE IDTable1=@IDTable1">
<SelectParameters>
<asp:ControlParameter ControlID="Grid_Table1" Name="IDTable1" PropertyName="SelectedValue"/>
</SelectParameters>
</asp:AccessDataSource>

<asp:DetailsView id="Details_Table1" DataSourceID="Data_Table1_detaljno" Runat="Server"
AutoGenerateRows="False"
DataKeyNames="IDTable1"
OnItemInserting="Validate_Insert_Data"
OnItemInserted="Display_Insert_Msg"
OnItemUpdating="Validate_Update_Data"
OnItemUpdated="Display_Update_Msg"
OnItemDeleting="Confirm_Delete"
OnItemCommand="Get_Command"
BorderStyle="Outset"
BorderWidth="1"
CellPadding="3"
GridLines="Vertical">

<Fields>

<asp:TemplateField HeaderStyle-BackColor="#E0E0E0" HeaderStyle-Font-Bold="True"
HeaderStyle-HorizontalAlign="Right" ItemStyle-VerticalAlign="Top"
ItemStyle-BackColor="#E0E0E0" ItemStyle-ForeColor="#FF0000">
<HeaderTemplate>
UREĐIVANJE:
</HeaderTemplate>
<ItemTemplate>
<asp:Button ID="Button1" CommandName="Edit" Text="PROMJENI" Font-Size="8pt" Width="75" Runat="Server"/>
<asp:Button ID="Button2" CommandName="New" Text="NOVI" Font-Size="8pt" Width="75" Runat="Server"/>
<asp:Button ID="Button3" CommandName="Delete" Text="OBRIŠI" Font-Size="8pt" Width="75" Runat="Server"/>
<asp:Label id="ConfirmDelete" Visible="False" EnableViewState="False" Runat="Server">
<asp:Label ID="Label1" Text="Sigurno obrisati zapis?" ForeColor="Red" EnableViewState="False" Runat="Server"/>
<asp:Button ID="Button4" Text="DA" CommandName="Yes" Font-Size="8pt" Width="75px" Runat="Server"/>
<asp:Button ID="Button5" Text="NE" CommandName="No" Font-Size="8pt" Width="75px" Runat="Server"/>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:Button ID="Button6" CommandName="Update" Text="POTVRDI" Font-Size="8pt" Width="75" Runat="Server"/>
<asp:Button ID="Button7" CommandName="Cancel" Text="ODUSTANI" Font-Size="8pt" Width="75" Runat="Server"/>
</EditItemTemplate>
<InsertItemTemplate>
<asp:Button ID="Button8" CommandName="Insert" Text="UBACI" Font-Size="8pt" Width="75" Runat="Server"/>
<asp:Button ID="Button9" CommandName="Cancel" Text="ODUSTANI" Font-Size="8pt" Width="75" Runat="Server"/>
</InsertItemTemplate>
</asp:TemplateField>

<asp:BoundField DataField="IDTable1" ReadOnly="False" HeaderText="OZNAKA: "
HeaderStyle-BackColor="#E0E0E0" HeaderStyle-Font-Bold="True"
ItemStyle-VerticalAlign="Top"/>

<asp:BoundField DataField="Ime" HeaderText="IME: " HeaderStyle-BackColor="#E0E0E0" HeaderStyle-Font-Bold="True"
ItemStyle-VerticalAlign="Top"/>
<asp:BoundField DataField="Prezime" HeaderText="PREZIME: " HeaderStyle-BackColor="#E0E0E0" HeaderStyle-Font-Bold="True"
ItemStyle-VerticalAlign="Top" />

</Fields>

</asp:DetailsView>

</div>
</form>
</body>
</html>
 
Back
Top