Client-Side User Confirmation Within DataGrid

S

simon_eyer

Hi, I use a datagrid with a delete command. I create a validation on
the delete command and i have a problem: the confirmation message is
supposes to appear each time I do this command but it appear just
sometimes. Is anyone can tell me how to get this message everytime I
use this command ?
thanks
this is my code in the aspx.vb :

Private Sub DataGrid1_ItemDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.DataGridItemEventArgs) Handles
DataGrid1.ItemDataBound

If (e.Item.ItemType = ListItemType.Item) Then
Dim control As WebControl
For Each control In e.Item.Controls
If CType(e.Item.Controls(4).Controls(0),
LinkButton).CommandName = "Delete" Then
CType(e.Item.Controls(4).Controls(0),
WebControl).Attributes.Add("onclick", "test()")
End If
Next


End If

End Sub
Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.DeleteCommand
cnn.Open()
Dim Sql As String
Dim matrans As OdbcTransaction = cnn.BeginTransaction
Dim cmd As New OdbcCommand
DataGrid1.EditItemIndex = e.Item.ItemIndex
Sql = "Delete from composition where fiberid=" &
e.Item.Cells(0).Text & "and tuileid=1"
DataGrid1.EditItemIndex = -1
cmd.Connection = cnn
cmd.Transaction = matrans
Try
cmd.CommandType = CommandType.Text
cmd.CommandText = Sql
cmd.ExecuteNonQuery()
matrans.Commit()
Catch ex As Exception
Response.Write(DataGrid1.DataKeyField)
Response.Write(ex.Message())
Finally
cnn.Close()
ActualiserListe()
End Try
End Sub

.. This is what i put in apx:

<script language="JavaScript" />
<!--
function test()
{
if (window.confirm("Do you want to delete?"))
{
}
else
{
event.returnValue = false;
}
}
//-->
</SCRIPT>
<form id="Form1" method="post" runat="server">
<table width="1136" border="2">
<TR><td>
<asp:datagrid id="DataGrid1" runat="server" Width="560px"
AutoGenerateColumns="False" Height="106px">
<Columns>
<asp:BoundColumn Visible="False" DataField="fiberid" ReadOnly="True"
HeaderText="Numfibre"></asp:BoundColumn>
<asp:TemplateColumn HeaderText="Fibre">
<ItemTemplate>
<asp:Label id=lblfibredg runat="server" Text='<%#
Container.DataItem("namefiber") %>'>
</asp:Label>
</ItemTemplate>
<EditItemTemplate>
<asp:DropDownList id="lstdg" runat="server"></asp:DropDownList>
</EditItemTemplate>
</asp:TemplateColumn>
<asp:BoundColumn DataField="pourcentage"
HeaderText="Pourcentage"></asp:BoundColumn>
<asp:EditCommandColumn ButtonType="LinkButton" UpdateText="Enregistrer
modification" HeaderText="Modifier la ligne"
CancelText="Annuler" EditText="Modifier"></asp:EditCommandColumn>
<asp:ButtonColumn Text="Supprimer" HeaderText="Supprimer la ligne"
CommandName="Delete"></asp:ButtonColumn>
</Columns>
</asp:datagrid></td></tr>
</table>
</form>
 
K

Ken Cox [Microsoft MVP]

Hi Simon,

Is your test for the ItemType correct? Don't forget that content also
appears in alternating item types. You probably need something like this,

If e.Item.ItemType = ListItemType.Item Or _
e.Item.ItemType = ListItemType.AlternatingItem Then

Let us know?

Ken
Microsoft MVP [ASP.NET]
 

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,969
Messages
2,570,161
Members
46,710
Latest member
bernietqt

Latest Threads

Top