473,395 Members | 1,411 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Client-Side User Confirmation Within DataGrid

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>

Jun 28 '06 #1
2 1958
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]

<si********@hotmail.com> wrote in message
news:11**********************@x69g2000cwx.googlegr oups.com...
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>

Jun 29 '06 #2

Hi Ken,
I try your code and it's working great now. Thank you

Jun 29 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: news.microsoft.com | last post by:
Hi I write dll library which one of it component will be Net socket communication. Communication is working very good, but i've got problem when client is connecting. When server is started,...
0
by: Tim Northrup | last post by:
Help! We have DB2 V7.2 (fixpak 12) installed on Windows2003 Server, and the latest V7.2 client installed on another system. The DB2CODEPAGE on all systems is set to 1208, and the database was...
2
by: Rhino | last post by:
I am trying to verify that I correctly understand something I saw in the DB2 Information Center. I am running DB2 Personal Edition V8.2.1 on Windows. I came across the following in the Info...
0
by: Harley | last post by:
Hello, I am just learning the tcp/ip functions etc under vb.net so please look over me if this is obviouse. I have been all over looking into any functions that I didn't totaly understand and...
2
by: Delmar | last post by:
I need to build Web Application that will generate a client to execute some operations. Each client has running silent application. Maybe somebody can advice me what can I do ? Thank you.
2
by: Macca | last post by:
My app has an asynchronous socket server. It will have 20 clients connected to the server. Each client sends data every 500 millisecondsThe Connections once established will not be closed unless...
2
by: J Huntley Palmer | last post by:
I am having a horrific time integrating uw-imap's c-client for imap support in php. The problem is a whole bunch of "Text relocation remains referenced against symbol" errors during linking....
5
by: Yossarian | last post by:
I have a handheld running CE .NET 4.2 and I am using c# with framework 1.1 to develop a solution for syncing data that is on the handheld with the local pc. Our handheld cradles only support...
2
by: nsaffary | last post by:
hi I hava a client/server program that run correctly when i run it in one computer(local) but when I run client on a one computer and run server run on another, connection does not stablish.(I set...
4
MMcCarthy
by: MMcCarthy | last post by:
http://bytes.com/images/howtos/projectscope_blocks.jpgAs a freelance IT consultant for over 10 years, I’ve come to appreciate well defined project scopes. A project scope is a common understanding...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.